faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

42 of 47 people (89%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can i compare the values of two text fields?

Feb 15th, 2001 20:00
Tom Kopke, Mark Neal,


You can use a function to compare two text fields of NAME values of 
your choice.
     function compare(form) {
       name1 = form.name1.value;
       name2 = form.name2.value;
       if (name1 != name2) {
         alert ("\nThe entries do not match. Please re-enter.")
         return false;
       }
         else return true;
     }
Execute the function with your favorite function call such as "onclick"
If the two fields don't match, a Javascript popup window appears with 
the text shown above