SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast nishantk's Avatar
    Join Date
    Sep 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with date

    Hi ,
    i need the modified verson of following java script ,current script shows current date and days in current month ,but i want to modify it in such way so it should not show previous days from today eg-: if today is 20 th nov then it should not show 19,18......
    <script type="text/javascript">
    window.onload = function(){
    document.getElementById('d').setAttribute('disabled', '');
    document.getElementById('m').setAttribute('disabled', '');
    var now = new Date();
    now.setDate(now.getDate() + 7);
    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    for(var i = 1; i <= 31; i++){
    var j = document.getElementById('d').options.length;
    document.getElementById('d').options[j] = new Option(i, i);
    if(i == now.getDate()) document.getElementById('d').options[j].selected = true;
    }
    for(var i = 1; i <= 12; i++){
    var j = document.getElementById('m').options.length;
    document.getElementById('m').options[j] = new Option(months[now.getMonth()]+' '+now.getFullYear(), (now.getMonth() + 1)+'_'+now.getFullYear());
    if(i == 1) document.getElementById('m').options[j].selected = true;
    now.setMonth(now.getMonth() + 1);
    }
    }
    </script>
    thankx in advance

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Changing the line:
    Code:
    for(var i= 1; i <= 31; i++) {
    to
    Code:
    for(var i=now.getDate(); i <= 31; i++) {
    should do the trick.

    There is one weird thing I don't understand why it is done in your script:
    Code:
    now.setDate(now.getDate() + 7);
    That will set the date 7 days ahead, so if today is 14, it'd think today was the 21st. If that is the intended use, then you should be good. If it isn't, you should probably remove that line.

  3. #3
    SitePoint Enthusiast nishantk's Avatar
    Join Date
    Sep 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you "samanime" 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
  •