RSjoomla! - Quality Joomla! Components

My Account






Lost Password?
No account yet? Register

Newsletter Subscribe

If you would like to be one of the first people to hear about the release of our new components then make sure you have subscribed to our announcements list! We won't bug you with unnecessary stuff.




RSform! Logo User Guide
RSform! - Form management component » Manage forms » Adding custom scripts to the form

Adding custom scripts to the form 

How to compare two fields using Javascript [Read All]

In this article we will describe how to create a simple form with RSform! 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 inputed by the user is correct.

You can start by creating a new form with the following settings:

Form Title: Compare
Form Name: Compare

The next step is to populate the form with the following fields:

  1. Email field 1
    Field id: email1
    Field Title: Email1
    Validation: email
    Field Type: text

  2. Email field 2
    Field id: email2
    Field Title: Email2
    Validation: email
    Field Type: text

  3. Submit button
    Field id: submit
    Field Title: Compare
    Validation: --none--
    Field Type: submit button

  Save the new fields created.

On the "Form Style" tab type the following code right after " action="{action}" ":

        onsubmit="return checkEmail(this);"
        
At the the end of form tag (after ) you will have to type the following JavaScript:

 
function checkEmail(theForm) {
   if (theForm.email1.value != theForm.email2.value)

{
  alert('Those emails don\'t match!');
  return false;
  }

else {
  return true;
  }
  return true
}

Click "Save" and that's it.