asp_web_howto thread: Dynamic validation with ASP and Javascript.
I am not sure how to do form validation for field dynamically generated
by
my ASP code.
Kindly advice me how I can solve this problem.
First i have a form which ask my users how many record that they want
for
data entry. Then the ASP will
generate the number of set of form field for data entry.
I am able to write Javascript to check for a valid passport expiry date.
But
it only work for the first record.
If the form generate more than one records... validation is not done for
the
rest of the records.
How can i do validation to check all the records have a valid date and
enforce the field is required for all the records?
Thank You
Specific no.of adult/record for data entry.
-----------------------------------------
Please enter the number of adult : <input type="text" name="Adult">
ASP code to generate the form
--------------------------------
<% If CInt(Request.Form("Adult")) > 1 Then
For i = 2 to CInt(Request.Form("Adult"))
Response.Write "<tr>" & _
"<td>" & i & "</td>" & _
"<td><input type=text name=Adultname
maxlength=40 size=15></td>" & _
"<td><select name=AdultSex>" & _
" <option
value=Male>Male</option>" & _
" <option
value=Female>Female</option>" & _
"</select></td>" & _
"<td><input type=text
name=Adultpassport
size=9 maxlength=9></td>" & _
"<td><input type=text
name=Adultexpiry
size=10 maxlength=10></td>" & _
"<td><input type=text name=Adultdob
size=10
maxlength=10></td>" & _
"<td><input type=text
name=Adultnation
size=10 maxlength=40></td>" & _
"</tr>"
Next
End If %>
<SCRIPT Language="JavaScript">
function Verifyfield(){
if (document.frm.First.value == "") {
alert("Required: Departure Date");
document.frm.First.focus();
return false
}
else if (document.frm.Adultexpiry.value == "") {
alert("Required: Passport Expiry Date");
document.frm.Adultexpiry.focus();
return false
}
else if (document.frm.Adultdob.value == "") {
alert("Required: Passport Expiry Date");
document.frm.Adultdob.focus();
return false
}
else
return true;
}
</script>