Results 1 to 7 of 7

Thread: alert when the user selects the date that is less than the date today

  1. #1
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default alert when the user selects the date that is less than the date today

    PHP Code:
    <?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?
    Last edited by abs0lut; 08-21-2008 at 07:28 AM.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Try to have this:
    Code:
    <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.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    thanks, when the alert says "error", the date entered by the user will not insert into the database.

  4. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    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.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  5. #5
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    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?
    Last edited by abs0lut; 08-21-2008 at 07:46 AM.

  6. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Oh, my bad. I misread your post. Try to add highlighted instead:
    Code:
    <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>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  7. #7
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    thank you very much

Bookmarks

Posting Permissions

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