Title: Multiple Forms Email validation on a single page using javascript
Last modified: August 22, 2016

---

# Multiple Forms Email validation on a single page using javascript

 *  [Abu Bakar](https://wordpress.org/support/users/absikandar/)
 * (@absikandar)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/multiple-forms-email-validation-on-a-single-page-using-javascript/)
 * I am developing a WordPress Widget Plugin that inserts as many as you want email
   input forms in a widget.
 * I am using the following code to validate email fields
 *     ```
       function validateForm(form) {
       var x = document.forms["twb_form"]["email"].value;
           var atpos = x.indexOf("@");
           var dotpos = x.lastIndexOf(".");
   
               if (x == null || x == "" || atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
   
               document.getElementById('errorMSG').innerHTML = 'Please enter a valid email address';                   
   
               return false;
               }
       }
       ```
   
 * The problem is that validation error always display along the very first form
   on page regardless of other forms… This is because of the div #errorMSG
 * I know this can be solved using some kind of PHP tricks but I can’t figure it
   out.
 * Every form on the page is being applied a separate ID … widget-id-1, widget-id-
   2 and so on…
 * How can I associate each validation message with a widget-id ?

The topic ‘Multiple Forms Email validation on a single page using javascript’ is
closed to new replies.

## Tags

 * [form](https://wordpress.org/support/topic-tag/form/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [multiple](https://wordpress.org/support/topic-tag/multiple/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 0 replies
 * 1 participant
 * Last reply from: [Abu Bakar](https://wordpress.org/support/users/absikandar/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/multiple-forms-email-validation-on-a-single-page-using-javascript/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
