Thứ Hai, 2 tháng 9, 2013

RSForm!Pro - How to compare two fields using Javascript

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. In the "Edit form" you can enter these values:


  • Form Title: Compare
  • Form Name: Compare


  • The next step is to populate the form with the following components:
    1. Email field 1 - Textbox
      Name: email1
      Caption: Email1
      Required: Yes
      Validation: Your validation message here

      Click "Save" next to the component's settings
    2. Email field 2 - Textbox
      Name: email2
      Caption: Email2
      Required: Yes
      Validation: email

      Click "Save" next to the component's settings
    3. Submit button
      Name: compare
      Caption: Compare
      Reset: No
      Additional Attributes: onclick="return checkEmail('email1', 'email2');"

      Click "Save" next to the component's settings

    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;
    }
    }
    </script>

    Click "Save" and that's it.

0 nhận xét:

Đăng nhận xét