[thelist] javascript dynamic loop
Brian Cummiskey
Brian at hondaswap.com
Tue Nov 29 17:13:24 CST 2005
I wrote a simple (well, i thought it was :P) function for a simple
data-entry check on a form.
On the previous page, there is a drop down with 0-5 in it, to select how
many children one has.
On this page, i ask for the ages of the children, displaying a box for
each child until the count is up.
I want to make sure that an age is entered for each child.
function validate2()
{
var theform = document.getElementById("frmdefault");
var numkids = 0; // initiallize the variable
numkids = 3; // this is ASP derrived from the POST data
for (j=1; j=numkids; j++)
{
age = eval("childage_"+j);
kidage = theform.age.value;
if (kidage == "")
{
alert("Please enter the age of child "+j);
return false;
}
}
theform.action="order_upsell.asp"
theform.method="post";
theform.submit();
}
The problem is that no matter how many children i select, the last one
will always come up undefined. In this example, i selected 3 kids.
Error: childage_3 is not defined
Source File: /order_kids.asp?act=kids
Any ideas why the last one is always undefined?
My form is built via an asp loop which i write out later in the source:
<%
for i = 1 to numkids
mytable = mytable & "Child "& i &" Age: <input type=""text""
name=""childage_"& i &""" size=""5"" maxlength=""3"" /><br />" & VbCrLf
next
%>
All of these elements populate correctly, and the "last" one is always a
valid input name
Thanks in advance.
-Brian
More information about the thelist
mailing list