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
|