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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tricky Little Problem

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
0
0
US
Guys,

I am very new to the whole Javascript thing and am looking for some assistance. I don't even know if it is possible to do what I want to do. I have a "dynamic" form in that when it comes to validation I won't have a definite idea how many rows of input boxes I will have.

One input row has 6 input text boxes ( 3 must be numeric and one must be a date ). They are named line1, delivery1, qty1, partid1, description1 and date1. However, once the user fills in these fields, they can choose to enter another part order. Thus, a second row of input boxes is displayed. ( i.e. line2, delivery2, qty2,......). When it comes to final validation, I won't know what the names of all the fields to be validated - i.e. I can't hardcode them into a validation script.

However, I have a hidden form field which stores the number of rows in the form. When it comes to order submission, I need to validate the contents of all the input fields. Is there some way that I can do something like:

for (i=0; i<document.myform.numrows.value; i++) {
if (document.myform.Qty(i) =&quot;&quot;) { // I know this is not right but this is the kind of thing I want to do
alert (&quot;Enter a quantity value in row i&quot;)
}
}
 
One thing I usually do is give each field a unique name. Assign the fields a letter, then add the row number to it.

line1
delivery1
qty1
partid1
description1
date1

Then when you add the next line rename change the names to

line2
delivery2

and so forth. You can use 'delivery' + iLineNumber to do this.

When you go to validate you can do this…

for (iX = 1; iX <= iTotalLines; iX++)
{
functionValidate(form['delivery' + iX]);
functionValidate(form['qty1' + iX]);
...
}

You can kinda see what is going on here.

Hope this helps.

 
or you couldus something like this:

var x = document.formname;
for(var i = 0; i < x.elements; i++)
{
if(/^\s*$/g.test(x.elements.value))
{
alert('please enter a value into field '+x.elements.name);
x.elements.focus();
}
}
luciddream@subdimension.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top