Classic ASP BasicsFor beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I want to perform some validation before a user submits a form. Is there any way for me to check each field to see if it's been filled in by the user. Right now, I have to manually add these to my script. I thought maybe I could use javascript to scroll through all fields to see if they'd been filled in or not. Here is my current code below. In my example you see that I have two if statements, one for each field on my form. What if I had 10 or 20 fields on my form. Assuming they are all required fields, rather than keying in 10 or 20 if statements, can I scroll through the fields instead? Thanks
function validateForm(theForm) {
if (!validRequired(theForm.begindate,"Begin Date"))
return false;
if (!validRequired(theForm.enddate,"End Date"))
return false;
return true;
}
function validRequired(formField,fieldLabel) {
var result = true;
if (formField.value == "")
{
alert('Please enter a value for the "' + fieldLabel +'" field.');
formField.focus();
result = false;
}
return result;
}