By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,054 Members | 902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,054 IT Pros & Developers. It's quick & easy.

javascript conflict

100+
P: 229
hi, I have two javascript form validation scripts.

Although the forms have different names, one of the scripts overrides the other and validates both. They have the same onsubmit, and one has a unique name (contact) and I cannot see why it is affecting the others search form which doesnt have a name.

Expand|Select|Wrap|Line Numbers
  1. onsubmit="return validate_form(this)"
the search validation is

Expand|Select|Wrap|Line Numbers
  1. function validate_required(field,alerttxt)
  2. {
  3. with (field)
  4. {
  5. if (value==null||value=="")
  6.   {alert(alerttxt);return false}
  7. else {return true}
  8. }
  9. }function validate_form(thisform)
  10. {
  11. with (thisform)
  12. {
  13. if (validate_required(SearchWord,"Please enter a value for the \"search word\" field!")==false)
  14.   {SearchWord.focus();return false}
  15. }
  16. }
and the form validation is

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. <!--
  4.  
  5. function validate_form ( )
  6. {
  7.     valid = true;
  8.  
  9.         if ( document.contact.ToName.value == "" )
  10.         {
  11.                 alert ( "Please fill in the 'Recipients Name." );
  12.                 valid = false;
  13.         }
  14.   if ( document.contact.ToEmail.value == "" )
  15.         {
  16.                 alert ( "Please fill in the 'Recipients Email' box." );
  17.                 valid = false;
  18.         }
  19.   if ( document.contact.FromName.value == "" )
  20.         {
  21.                 alert ( "Please fill in the 'Your Full Name' box." );
  22.                 valid = false;
  23.         }
  24.   if ( document.contact.FromEmail.value == "" )
  25.         {
  26.                 alert ( "Please fill in the 'Your Email' box." );
  27.                 valid = false;
  28.         }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.         return valid;
  35. }
  36.  
  37. //-->
  38.  
  39. </script>
They are the only two that seem to work back to IE5 that I can find.

How do I make them with unique so one does not override the other. At the moment the search validation comes up with enter the correct email,name,etc. It should just say enter a search term.
Any help would be greatly appreciated.


Thanks
Richard
Sep 30 '07 #1
Share this Question
Share on Google+
1 Reply


100+
P: 229
Hi, I sorted it out. I just changed the function. They were identical on both scripts.
Thanks
Richard
Sep 30 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.