View Single Post
12-13-2007, 02:39 PM
#4
tristan is offline tristan
Status: I'm new around here
Join date: Dec 2007
Location:
Expertise:
Software:
 
Posts: 8
iTrader: 0 / 0%
 

tristan is on a distinguished road

  Old

Your && should be working.
You need to give each form field a name attribute. You should also give your form a name attribute. Then, to access your elements, you can say:
Code:
document.formName.elementName
//if your form was called "brokenForm" and you had an element with name "firstName" you could do:
if(document.brokenForm.firstName.value == "") {
//raise your error
}
Now, that said, I might go about this a little differently. My approach would be to initiate an error string at the top of the validation function and set it equal to "". Then, reset any highlighting you've done on the form fields (looks like you want to color them differently when theres an error). Analyze each field individually, and as you find errors, highlight that field as you'd like (by style changes) and add a line to the error string, separating each with a '<br/>' or <p> tags or something of the sort. At the end of the function, if error != "", you found an error somewhere. Populate your element with ID 'errors' (which you also happen to have set up with a red, bold style) with the error string, and return false. Otherwise, return true.


Hope you can make sense of that! Its early.....