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
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts

    asp form validation help

    Hello,



    I am try to create a search form and require a user to select

    1. Student and

    2. either a "alldates" checkbox or "Start" and "End" dates.



    This is what I did, but it never works for me.



    What did I do wrong? How do I modify this code to make it worked.



    Code:
    <form method=POST action="Student.asp" name="frmStudent" onSubmit="return checkForm();">
    
    <%       if not rsStudent.eof then %>
    
                            <select name="SelectStudent" size="1" title="Select a Student">
    
                                        <option value="1" SELECTED>Select a Student</option>
    
                                        <%       do until rsStudent.eof %>
    
                                        <option><%= rsStudent("Names") %></option>
    
                                        <%       rsStudent.MoveNext
    
                                                    loop    %>
    
                            </select>
    
                <%       end if
    
    %>
    
                All Dates:</span><input type="checkbox" Name="alldates" value="1"><br />
    
                <input name="Start" id="Start" class="" type="text" size="10" maxlength="12" onBlur="checkdate(this)" value=""><br />
    
                <a href="javascript:;" onclick="displayDatePicker('Start', this);"><img src="img/calendar.gif"></a>
    
                <input name="End" id="End" class="" type="text" size="10" maxlength="12" onBlur="checkdate(this)" value="">
    
                <a href="javascript:;" onclick="displayDatePicker('End', this);"><img src="img/calendar.gif"></a><br />
    
    <input type="Submit" name="btnSubmit" value="Search">
    
    </form>
    
     
    
    <!--Search.asp -->
    
    <%
    
    If Request("rsTraveler") = "1" Then
    
                errorForm "Please select a Student!"
    
    ElseIf (Request("alldates") = "") OR (Request("Start") = "" AND (Request("End")) = "" OR (Request("alldates") = "") Then
    
                errorForm "Please select a Date!"
    
    End If
    
    Else
    
    ---Show the results
    
    %>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    *sigh*

    The names you use in processing a <form> submission must match the names of the fields in the <form> that was submitted!!!

    LOOK HERE:
    Code:
    <select name="SelectStudent" ...>
    But then look here:
    Code:
    If Request("rsTraveler") = "1" Then
    ********

    Then this statement makes no sense at all:
    Code:
    ElseIf (Request("alldates") = "") OR (Request("Start") = "" AND (Request("End")) = "" OR (Request("alldates") = "") Then
    First of all, you are *REPEATING* the Request("alldates"). And in a way so wrong I don't have time to explain it.

    Secondly you are saying "if the user did not check 'alldates' *OR* if the user didn't input start and end dates, it's an error. So suppose the user does not check 'alldate'. And the user does put in start and end dates. You will *STILL* mark that as an error, because of the OR condition!!!

    Your logic is completely backwards!
    Code:
    ElseIf Request("alldates") = "" AND ( Request("Start") = "" OR (Request("End")) = "" ) Then
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It worked perfect.
    Big thanks.
    Have a nice day!


  •  

    Posting Permissions

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