This is a discussion on "New to JavaScript" within the JavaScript Forum section. This forum, and the thread "New to JavaScript are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
New to JavaScript
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
New to JavaScript
Hi.
I am new to JavaScript and to this forum. I hope somebody can help me with this Script: I have a page with a form validator. It works fine. However, I have 2 forms on this page and want to use the validation script for either form 1 or form 2. The fields on the form have different names. Here is the script :: <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function validate() { var theMessage = "Please complete the following: \n-----------------------------------\n"; var noErrors = theMessage // make sure field is not blank if (document.form1.First_Name.value=="") { theMessage = theMessage + "\n --> Your First Name"; } // If no errors, submit the form if (theMessage == noErrors) { return true; } else { // If errors were found, show alert message alert(theMessage); return false; } } // End --> </script> Question:: In my form 2 I have a field called "Friends_First_Name". What do i have to do that the script works either on form 1 or form 2? Any help would be great. Regards Syd |
|
|
|
|||
|
Re: New to JavaScript
Establish which forms 'submit' button caused the routine to be called and use if...else statements. E.g., below:
|
|
|||
|
Re: New to JavaScript
Many thanks Geoff.
I'll try that and came back later. Syd |
|
|||
|
Re: New to JavaScript
Thanks again, I have solved the problem:
Each form is using the same validation function; I gave the 2 functions different names so each for accesses the appropriate one! Cheers Syd |
![]() |
| Tags |
| function validate |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| php and javascript | yvettesio | JavaScript Forum | 8 | Mar 14th, 2007 23:18 |
| JavaScript | cbrams9 | JavaScript Forum | 1 | Sep 20th, 2006 17:35 |
| using xml in javascript | shailu | JavaScript Forum | 0 | Jul 25th, 2006 07:36 |
| Can someone help me with this javascript | Galaxyblue | JavaScript Forum | 2 | Mar 11th, 2004 12:18 |
| what does \\ mean in javascript | jenjen1018 | JavaScript Forum | 5 | Jan 6th, 2004 17:05 |