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

Form Validation Question

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Guys,

I am very new to the whole Javascript thing and am looking for some assistance. 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. The input fields are named in the format of Qty1, Qty2, Qty3,...DueDate1, DueDate2, DueDate3,...,etc for each row of inputs. I have the number of rows stored as a hidden field in the form. 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;)
}
}
 
Instead of naming your form element Qty1, Qty2 ... you have to use the same name like Qty afer, you make an eval like myElement = eval(&quot;document.forms[0].Qty&quot;); to make an Array of those Element

example :

myElement = eval(&quot;document.Forms[0].Qty&quot;);
for (var i = 0; i < myElement.length; i++) {
if (myElement.value + &quot;&quot; == &quot;&quot;) {
alert(&quot;Enter a quantity value in row &quot; + i);
}
};

I hope that it will help you, let me know if it fix your problem
 
SeAL,

Thanks for the response but I had already got it working. I used the following:

for (i=0; i<document.myform.numrows.value; i++) {
if (eval(&quot;document.myform.Qty&quot; + i).value =&quot;&quot;) {
alert (&quot;Enter a quantity value in row&quot; + i)
}
}
Mise Le Meas,

Mighty :)
 
it's exactly the same things except that with the sample i gave you, you don't care of the row numbers 'cose you use the length of the Array ;)

But I forget something in my sample :

if (myElement.value + &quot;&quot; == &quot;&quot;) {
alert(&quot;Enter a quantity value in row &quot; + i);
}

and not
if (myElement.value + &quot;&quot; == &quot;&quot;) {
alert(&quot;Enter a quantity value in row &quot; + i);
}

Regards
 
mighty, this : if (eval(&quot;document.myform.Qty&quot; + i).value =&quot;&quot;) won't work !!
read carefully SeAL examples - *they* are correct
 
iza,

The code below is taken striaght fromy OPERATIONAL page. This works fine.

if ((isNaN(eval(&quot;document.ProdForm.Qty&quot; + i).value)) || (eval(&quot;document.ProdForm.Qty&quot; + i).value == &quot;&quot;)) {
alert(&quot;You must enter a NUMBER in the Quantity Field in row &quot; + i);
eval(&quot;document.ProdForm.Qty&quot; + i).focus();
return false;
} // End of IF Loop
Mise Le Meas,

Mighty :)
 
! fonts are way tooo small here, and i misread the () : i thought it was :
(eval((&quot;document.myform.Qty&quot; + i).value)
so it sounds like it's working for you now - fine !
SeAL to see your you have to UNcheck &quot;process tgml&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top