Click to See Complete Forum and Search --> : validation of form elements within div tags


jeffl183
08-17-2003, 04:43 PM
In order to create a more user-friendly form, I put logical chunks of the form into layers <div>s and then set their visibility, based on other events. (The layers are nested inside the form.)

That works fine, but I'm having trouble validating the form data. My intention was to validate one layer at a time, and then move on to the next.

I'm a newbie, with regard to using the DOM, and testing something like "document.formName.inputName.value == "" is throwing a JavaScript error, indicating that the above is not an object.

Any suggestions how I retrieve values in this context?

Thanks!

Khalid Ali
08-17-2003, 05:16 PM
What you can do is to get all the childNodes of the div tag and then validate any form elements that may be in that div.
if you have reference to the div then you can get all input elements like this

var formEl = divRef.getElementsByTagName("input");

formEl is an array of all the input elements that may be in this div you can loop through the array access each inpyt and validate it.

jeffl183
08-17-2003, 10:05 PM
Thank you. I'm truly greatful for the response, but I'm a little embarrased to say I'm not sure how to use the suggestion. I guess I'm more of a newbie than I thought.

If I wanted to reference the value of an input (say, "address") within a layer (say, "shipping") in a form (say, "ordform"), what would be the correct syntax? I've tried:

1. document.ordform.shipping.address.value
2. document.shipping.address.value
3. document.ordform.address.value
4. this.address.value

Sincerely, thanks for your help!

jeffl183
08-18-2003, 07:52 AM
After a night's sleep, I was able to use your suggestion and make it work.

Thanks for all your help, Khalid!