Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-11-2011, 06:31 PM   PM User | #1
jennypretty
Regular Coder

 
Join Date: Nov 2005
Posts: 225
Thanks: 2
Thanked 0 Times in 0 Posts
jennypretty is an unknown quantity at this point
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

%>
jennypretty is offline   Reply With Quote
Old 04-11-2011, 09:38 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
*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.
Old Pedant is offline   Reply With Quote
Old 04-12-2011, 03:34 PM   PM User | #3
jennypretty
Regular Coder

 
Join Date: Nov 2005
Posts: 225
Thanks: 2
Thanked 0 Times in 0 Posts
jennypretty is an unknown quantity at this point
It worked perfect.
Big thanks.
Have a nice day!
jennypretty is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:20 AM.


Advertisement
Log in to turn off these ads.