Click to See Complete Forum and Search --> : Form Validation for a Drop-Down List


devine
06-14-2006, 03:11 PM
Hi All,
I have a validation page for a form.
One of the fields is a drop-down list, where the default option is "Please select from list"

My validation code is:

<% IF Request.Form("Summary") <> "" AND Request.Form("Details") <> "" AND Request.Form("Rep") <> "Please Select From list" THEN


and form is validated.

But I don't think this is correct: Request.Form("Rep") <> "Please Select From list" THEN

What I'm trying to achvieve is if "Please Select From list" is passed, this is not valid, so I need the code for





Request.Form("Rep") = "Anthing other than Please Select From list" is valid.


As usual, your guidance is very appreciated!
Lynn

lmf232s
06-14-2006, 03:38 PM
Make the default value blank.

<select name=ddlTest>
<option value="">Please Select From list</option>
</select>

Then to check it

If Request.Form("ddlTest") = "" Then
errMsg = "Please Select a value from the list"
Else
'A value was selected, your good to go
End If

vanny
06-14-2006, 07:09 PM
Why not look at validating the option on the client side and not let them submit unless they complete the form, this saves you having to redirect them back to fill in the option.

Something like


<SCRIPT LANGUAGE=javascript>
<!--
function validate()
{
var sMessage = "Please complete the following mandatory fields\n"
sMessage = sMessage + "---------------------------------------------------------\n"
var incomplete = "no"

if(document.frmName.boxName[document.frmName.boxName.selectedIndex].value == "")
{
incomplete = "yes"
sMessage = sMessage + "- Please select a value\n"
}
if(incomplete == "yes")
{
sMessage = sMessage + "---------------------------------------------------------"
alert(sMessage)
}
else
{
document.frmName.submit()
}


You can either have a submit button or a normal button, I prefer normal button and use an onClick="validate()" to submit the page as this stop someone press enter to go to next field and getting the popup, but that is entirely up to you.

devine
06-15-2006, 10:12 AM
Hi,
Thanks to both of you for your responses.
I took lmf232s' advice and was a very quick and simple solution! (Not sure why I didn't think of it!)
Once again, many thanks!