...

View Full Version : vbscript form with .asp



briggsc
07-02-2004, 09:53 PM
Hi I am working on a form. The form has a field that needs to be required if the uses selects the option "Yes" from the a drop down menu. I used an If Then statement and it doesn't work. The form acts asif there is not function tied to the "Yes" option. Do anyone have any suggestions?

Here's what I'm talking about:


*****If Then Statement*****


If Request.Form("product_sold_option") = "Yes" Then
If Request.Form("product_sold") = "" Then
errs = addError("product_sold", "(Product sold is required)")
End IF
End If

If Request.Form("product_sold_option") = "Yes" Then
If Request.Form("acct_number") = "" Then
errs = addError("acct_number", "(Account number is required)")
End IF
End If





*********Body*********

<table>
<tr><td valign="top"><span style="color:#FF0000;">*</span>
Was there a Product/Service Sold?</td>

<b><td width="100%">
<select name="product_sold_option" id="product_sold_option"<%=BadFields("product_sold_option")%>>
<option value="">-Select One-</option>
<option value="yes">Yes</option>
<option value="no">No</option>
<option value="pending">Pending</option>
</select><%=BadText("product_sold_option")%></td></b>
</table>

glenngv
07-05-2004, 03:05 AM
The case doesn't match.

If Request.Form("product_sold_option") = "Yes" Then
...
<option value="yes">Yes</option>

You need to change the other to match the case or LCase/UCase it.
And you can check for "yes" option once only. It's efficient if you store the requested form data in variables because you will need them later in the code.


dim opt, sold, acct
opt = Request.Form("product_sold_option")
sold = Request.Form("product_sold")
acct = Request.Form("acct_number")
If opt = "yes" Then
If sold = "" Then
errs = addError("product_sold", "(Product sold is required)")
End If
If acct = "" Then
errs = addError("acct_number", "(Account number is required)")
End If
End If

Bullschmidt
07-05-2004, 11:20 PM
And if you just want to be sure a field isn't blank, here's a JavaScript validation resource (although I usually use ASP too):

WebDaily: Your daily source for Web Technology Tips and Tricks! - 10/27/1998
http://www.4guysfromrolla.com/webtech/102798-1.shtml
Just checks if fields filled in.

Javascript Field Validations -- Client Side Scripting by Nannette Thacker - 8/19/1999
http://www.shiningstar.net/articles/articles/javascript/javascriptvalidations.asp?ID=AW

Form Validation Using Javascript - 9/19/1998
http://www.4guysfromrolla.com/webtech/091998-1.shtml



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum