Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client-side validation with form collection

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
Hi,

I'm trying to do equivalent in client-side validation of where you loop through a collection of variables with the same name, i.e.:

For each item in Request.Form("AutoAge")
....
do something with item
Next

The above code is how I would do it on the server-side, but what about client-side? Is it something with document.MyForm.AutoAge(X).value? If so, how would you know how many times to do it?

Thanks,
Ray
 
wrbodine,

I believe you are looking for this:
Here in javascript (which should be your client-side scripting language):

var elem;

for (elem=0;elem<document.forms[0].elements.length;elem++){
}

where forms[0] could also be the name of the form.

This will loop thru all the elements in your form.

Mike

 
Thanks for the idea Mike, I tried that and elements.length gives me the total number of all the variables on the form (including variables with other names); I only want the number of those with a specific name (i.e., I have an unknown number of text boxes on the form all with the same name. How would I know how many of these text boxes there are?)
 
Try this.
Code:
for (var i = 0; i < document.forms[0].elements.length; i++) {
  if (document.forms[0].elements[i].name == &quot;elemname&quot;) {
    //ONLY THOSE ELEMENTS WITH THAT NAME
  }
}
ToddWW
 
Thanks Todd!

That does do what I want.

Actually I just found another way also:
document.all(&quot;variableName&quot;).length
 
Yep.. I've seen that used before as well. Good shortcut.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top