Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   validating the long form fields (https://www.warriorforum.com/programming/500370-validating-long-form-fields.html)

amrta 8th December 2011 12:51 AM

validating the long form fields
 
hello,

iam developing a website and i have a long form in tat. i have to validate all the fields. the method im using for validation is given below

if(document.getElementById('user').value==''){
alert ('please enter the valid username');
}

how can we add more than one field by this method (is ter any method tat we can write in single line).

Roll3rBoX 8th December 2011 04:04 AM

Re: validating the long form fields
 
not likely...different form elements need to be validated differently..!

rajprince 9th December 2011 02:43 AM

Re: validating the long form fields
 
Use JQuery,

dutchguy 10th December 2011 08:58 AM

Re: validating the long form fields
 
The previous answer use jQuery is the best answer.

If for whatever reason you don't want to use jQuery the alternative is as follows:

Create a javascript function for checking the value of a field and return true of false based on wether or not the required field is checked

Create an array containing all element names of the required fields you need to check

create a loop iterating over every element name in the array and calling the function you created. If false break out of the loop and display an error message.

Good luck. If nessescary PM me.

ricky pounting 12th December 2011 06:54 AM

Re: validating the long form fields
 
The best option is jquery but if you want to use your own way then use if else condition also very easy.


All times are GMT -6. The time now is 06:07 AM.