|
-
Oct 28th, 2000, 04:02 PM
#1
Thread Starter
Fanatic Member
hello,
I have a form w/ 15 items on it.
of those 15 four are Address,City,State,and Zip.
I need to make sure that if the user enters just the city or state or zip or address that I give them an alert that says "fill out the rest of the address".
right now I am using a TON of if statement. is there a way I can put those four fields into an array and loop through them for the validation?
if they don't fill out any of the four fields that is fine but if they fill out just one then I want to tell them to fill out all of them.
thanks.
-
Oct 28th, 2000, 11:44 PM
#2
Frenzied Member
If you give them all the same name. You will then need to access them from the request object once you submit the form like a collection item:
Request.Form("MyTextBox")(0)
Request.Form("MyTextBox")(1)
You can access them in code like:
for(i=0; i < 15; i++)
if(MyTextBox(i).value='')
window.alert("Fill them all out");
(Check my syntax on this Javascript stuff tho!)
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Oct 28th, 2000, 11:54 PM
#3
Thread Starter
Fanatic Member
it's not an ASP page
this is just an HTML page.
could I do the same thing? or something simalar with just javascript?
I need it to be client side validation.I thought I saw this done before but maybe it was using ASP.
dunno
thanks?
-
Oct 30th, 2000, 03:11 AM
#4
Hi, you could do something like this:
----------------------------------------
<!--
function checkme(myform)
{
if (myform.Name.value == "")
{
alert("The field Name must be filled in!");
myform.Name.focus();
return;
}
if (myform.Address.value == "")
{
alert("The field Address must be filled in!");
myform.Address.focus();
return;
}
if (myform.ZipCode.value == "")
{
alert("The field Zip Code must be filled in!");
myform.ZipCode.focus();
return;
}
if (myform.City.value == "")
{
alert("The field City must be filled in!");
myform.City.focus();
return;
}
if (myform.State.value == "")
{
alert("The field State must be filled in!");
myform.State.focus();
return;
}
if (myform.Country.value == "")
{
alert("The field Country must be filled in!");
myform.Country.focus();
return;
}
return true;
}
--------------------------------------------
You would of course call this function when the submit button is clicked.
-
Oct 30th, 2000, 09:35 AM
#5
Thread Starter
Fanatic Member
that is what I am doing right now.
but becouse it it not neccasary for the user to fill out the address I don't want to tell then to fill it unless they opt to (say they fill out just the city, or just the state)I
want to then alert them to fill out the rest of the address.
this is what it looks like now:
if
(myform.address.value !=0 && myform.city.value == 0 && myform.state.value ==0 && myform.zip.value == 0)
{
alert("fill out the city)"
}
I do this four times for each field. the user only gets the alert if they forget to fill out one of the fields.
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|