PDA

View Full Version : alert when the user selects the date that is less than the date today



abs0lut
08-21-2008, 06:11 AM
<?php
echo "Expiration Date:<br />";
echo"<label for='month'>Month: </label>";
echo"<select id='month' name='eMonth'>";
$month2=array("Jan"=>"1","Feb"=>"2","Mar"=>"3","Apr"=>"4","May"=>"5","Jun"=>"6","Jul"=>"7","Aug"=>"8","Sep"=>"9","Oct"=>"10","Nov"=>"11","Dec"=>"12");
foreach( $month2 as $name2 => $num){
echo '<option value="'.$num.'">'.$name2.'</option>';
}
echo"</select>";

echo"<label for='date'>day </label>";
echo"<select id='date' name='eDay'>";

for($j=1; $j<=31; $j++)
{
echo '<option>'.$j.'</option>';
}
echo"</select>";

echo "<label for='year'>Year: </label>";
echo"<select id='year' name='eYear'>";
for($l=2008; $l<=2038; $l++)
{
$cyr=date('Y');
if($l==$cyr){
echo '<option value="'.$l.'" selected="selected">'.$l.'</option>';
} else{
echo '<option>'.$l.'</option>';
}
}
echo"</select><br>";
?>
The user must select a date from the dropdown.
I need to display an alert message "error" when the user selects
jul 21, 2008 in the dropdown and the date today is aug 21, 2008
or the when the user selects the date that is less than the date today.
the user must select a date that is greater than the date today.
could you please help me?

rangana
08-21-2008, 07:15 AM
Try to have this:


<script type="text/javascript">
window.onload=function(){
document.getElementById('trig').onclick=function(){
var date=new Date(),month=date.getMonth(),day=date.getDate(),year=date.getFullYear(),
monthOpt=document.getElementById('month'), // id for month dropdown
dayOpt=document.getElementById('date'), // id for days dropdown
yearOpt=document.getElementById('year') ; // id for year dropdown.
if(monthOpt.value<=(month+1)&&dayOpt.value<=day&&yearOpt.value<=year)
alert('Error. The date today is: '+monthOpt.options[month].text+' '+day+' '+year+'.');
}}
</script>
<input type="button" value="Get Marvelled" id="trig">


See if it works.

abs0lut
08-21-2008, 07:26 AM
thanks, when the alert says "error", the date entered by the user will not insert into the database.

rangana
08-21-2008, 07:31 AM
It was not mentioned in the first thread you have, and I can't see anything in the 1st post that there was a connection in the DB.

Up the related codes, but I should inform you in advance that server-side is not my forte, I may/may not help.

abs0lut
08-21-2008, 07:38 AM
When the user press the ok or close the alert, the date entered by the user will not insert into the database. Isn't possible in javascript?

rangana
08-21-2008, 07:44 AM
Oh, my bad. I misread your post. Try to add highlighted instead:


<script type="text/javascript">
window.onload=function(){
document.getElementById('trig').onclick=function(){
var date=new Date(),month=date.getMonth(),day=date.getDate(),year=date.getFullYear(),
monthOpt=document.getElementById('month'), // id for month dropdown
dayOpt=document.getElementById('date'), // id for days dropdown
yearOpt=document.getElementById('year') ; // id for year dropdown.
if(monthOpt.value<=(month+1)&&dayOpt.value<=day&&yearOpt.value<=year){
alert('Error. The date today is: '+monthOpt.options[month].text+' '+day+' '+year+'.');
return false;}
}}
</script>

abs0lut
08-21-2008, 07:46 AM
thank you very much