PDA

View Full Version : Making an ASP field compulsary


Brad
09-04-2002, 01:40 PM
Hi,

I've done this before, but can't, for the life of me, remember how, and I can;t find the old code. I want to make a field produce an alert if it is not filled in, preferably when I submit the form.

Can anyone help,please ?

Thanks,
Brad.

raf
09-04-2002, 02:01 PM
if you want to do it before submitting (client-sided), go javascript. since this is a server-sided forum do it in the beginning of your asp with something like :

dim problem

problem="0"

If Len(requenst.form("field1") <="0" then 'if it's a blank field then
response.write("You have to enter something in field1")
problem=1
end if

if Len(requenst.form("field2") <="0" then
response.write("You have to enter something in field2")
problem=1
end if
...
if problem = "0" then 'to prevent the code from running further if their wer problems
the code that need to be run
else
response.write("<a href='javascript:history.back();'>Back</a>")
end if

(you can shorten the code with a for "each... in..." loop buth i usually check if their is anythin entered, if it's numeric, if it's not to big/smal and then you can't use that sort of loop)