How to compare two fields using Javascript

In this article we will describe how to create a simple form with RSForm!Pro with two email fields.

The following script will be used to compare the value of these fields so you can get a confirmation that the data inuted by the user is correct.

You can start by creating a new form and add 'Compare' as 'Form Title' and 'Form Name', second you will need to add two 'Textbox' fields named 'email1' and 'email2' and finally add a 'Submit Button' named 'Compare'. While editing this button, add in the 'Additional Attributes' area the following snippet:

onclick="return checkEmail('email1', 'email2');"

After you've setup these fields, go to the "CSS and Javascript" tab and paste the following code:

<script type="text/javascript">
function checkEmail(theForm)
 if (document.getElementById('email1').value != document.getElementById('email2').value)
alert('Those emails don\'t match!');
         return false;
    else {
         return true;

Click "Save" and test this form, you should receive an alert box if their values don't match.

41 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that