Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing value from drop-down list in form for validation

Status
Not open for further replies.

kevpho

Programmer
Jun 9, 2003
47
CA
Hi all,

I'm having some difficulties getting my form validation script to work properly. What I have right now is a drop-down menu that is empty by default. When the users complete the form and try to submit it without changing that drop-down menu, I want the form to catch it before its submitted and tell the user to enter a value.

I have a basic "if-then" statement to check if the drop-down menu value is empty, but no value seems to be passed through it, even if something is present. Here's the code for it:

<script language=&quot;VBScript&quot;>
Dim validation
Function CreateWR_onSubmit
validation = True
if Document.CreateWR.FloorSelect.Value = &quot;&quot; then
Msgbox &quot;Invalid data&quot;
validation = False
else
Msgbox &quot;Your entry has been updated.&quot;
end if

if validation = True then
CreateWR_onSubmit = True
else
CreateWR_onSubmit = False
end if
end Function
</script>

The name of the form is CreateWR and the drop down menu is FloorSelect. I just want to make sure that when the form is filled out, that a Floor is picked.

However, if I picked for example &quot;Ground Floor&quot;, it says there's invalid data. I made a msgbox to check if &quot;Document.CreateWR.FloorSelect.Value&quot; was working correctly, but it doesn't seem to be passing the values properly.

Any suggestions on what I need to do ? Any help is much appreciated.

Kevin
 
Had a look @ your script try this.


<script language=&quot;VBScript&quot;>
<!--
Function CreateWR_onSubmit()
if Document.CreateWR.FloorSelect.Value = &quot;&quot; then
Msgbox &quot;Invalid data&quot;
CreateWR_onClick=false
else
CreateWR_onSubmit = True
Msgbox &quot;Your entry has been updated.&quot;
end if

end Function
-->
</script>
 
I tried out the script Watty, and what happens is that whether or not there is something selected in the drop down menu (ex. ground floor), the &quot;Invalid Data&quot; msgbox shows up.

What I think is happening is that initially, the &quot;FloorSelect&quot; option is blank and has a value of &quot;&quot;. But when the value changes, the value is not passed properly because it still has a value of &quot;&quot; and that's why the &quot;Invalid Data&quot; msgbox shows up.

Now I know the problem, but how do I fix it? Someone told me I might be trying to pass the wrong value. The values in the drop down menu are text values.

Thanks a lot!
 
Never mind I fixed my problem. Stupid me I forgot to give my options values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top