Reply
Validate dates function partially not working
Old 05-09-2006, 07:11 AM Validate dates function partially not working
Super Talker

Posts: 145
Hi,

I have created a php page where the user selects a pick up date and drop off date from a pop up calendar
and submit the dates by clicking on the submit button. I have write a javascript function which checks
if the drop off date is after the pick up date.If it is not then an alert apperas informing the user for the error.

The code for the function:

PHP Code:
<script type="text/javascript">
function 
check()
{
           var 
dt1 Date.parse(document.form1.pickupdate.value+" "+document.form1.pickuphours.value+":00");
          var 
dt2 Date.parse(document.form1.dropoffdate.value+" "+document.form1.dropoffhours.value+":00");
     if(
dt1>dt2)
     {
          
alert("Please select a pick up date that is before the drop off date!");
     return 
false
      } 
}
</script> 
The code of the form:

HTML Code:
<form action=".php" method="post" name="form1" id="form1" onsubmit="check(this);">
<input name="pickupdate" type="text" size="18" id ="pickupdate" value="pick up date" class="body"/>
<a href="javascript:showCal('Calendar3')"><img src="datebutton.jpg" alt="dates" border="0" /></a>
                    
                         <select name="pickuphours" class="body">
                         <option selected value="pickuphour"> Pick up hour</option>
                         <option value="08:00">08:00</option>
                         <option value="09:00">09:00</option>
                         <option value="10:00">10:00</option>
                         <option value="11:00">11:00</option>
                         <option value="12:00">12:00</option>
                         <option value="13:00">13:00</option>
                         <option value="14:00">14:00</option>
                         <option value="15:00">15:00</option>
                         <option value="16:00">16:00</option>
                         <option value="17:00">17:00</option>
                         <option value="18:00">18:00</option>
                         <option value="19:00">19:00</option>
                         <option value="20:00">20:00</option>
                    </select>
                         
<input name="dropoffdate" type="text" size="18" value="drop off date" class="body" id="dropoffdate" />
<input name="date" type="text" size="4" value="days" class="body" id="date" style="position:absolute; left: 28px; top: 355px;"/>
<a href="javascript:showCal('Calendar4')"><img src="datebutton.jpg" alt="dates" border="0" /></a>

                      <select name="dropoffhours" class="body" onfocus="calcDays()">
                           <option selected value="dropoffhour"> Drop off hour</option>
                           <option value="08:00">08:00</option>
                           <option value="09:00">09:00</option>
                           <option value="10:00">10:00</option>
                           <option value="11:00">11:00</option>
                           <option value="12:00">12:00</option>
                           <option value="13:00">13:00</option>
                           <option value="14:00">14:00</option>
                           <option value="15:00">15:00</option>
                           <option value="16:00">16:00</option>
                           <option value="17:00">17:00</option>
                           <option value="18:00">18:00</option>
                           <option value="19:00">19:00</option>
                           <option value="20:00">20:00</option>
                      </select>
                      <input name="submit"  type="image" id="button" />
</form>
The function I have written is partially working and I will explain what the two problems are.
The first probllem is when the user select different month.
When the user select pick up date:10/05/2006 and drop off: 04/06/2006
an alert displays informing that the drop off date in not after the pick up date which normally should not have appeared.
Thus it is comparing the days(10>04) instead the whole date.

The second problem is that even the alert message appears teh form is been submited.

I would really appreciate your help.

Thank you,
Xenia
xenia is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-09-2006, 08:16 PM Re: Validate dates function partially not working
Novice Talker

Posts: 13
Location: Vancouver, BC
for problem 2, change the form "onsubmit" to:

onsubmit="return check();"

(need "return")
__________________
Visit my startup - Tooldle.com: $0 Web Plugin Tools for Web Designer
gumlor is offline
Reply With Quote
View Public Profile
 
Old 05-10-2006, 03:23 PM Re: Validate dates function partially not working
funkdaddu's Avatar
Web Design Snob

Posts: 636
Did the code I showed you in your other post on this not work?
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Reply     « Reply to Validate dates function partially not working
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12704 seconds with 13 queries