Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Arkansas
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vbscript form with .asp

    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>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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.
    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

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    478
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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/...ions.asp?ID=AW

    Form Validation Using Javascript - 9/19/1998
    http://www.4guysfromrolla.com/webtech/091998-1.shtml
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •