Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Question about displaying weeks for the whole year in a drop down list

    Hi..

    I just want to know how can I display Weeks in a drop down list per year.

    Thank you

  • #2
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    what do you mean?

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by webdev1958 View Post
    what do you mean?
    I want a select option of year and select options of list of week base on the year that I choose from the first select option.


    Thank you

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    What do you mean by "week base"? Do you mean populate the list with every (say) Monday in the year? Or what?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <select id="tst" size="1">
    </select>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Weeks(year,day,id){
     var srt,ary=[],z0=1,sel=document.getElementById(id),date,months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
     sel.options.length=0;
     sel.options[0]=new Option('Select Week');
     for (;z0<366+7;z0++){
      srt=new Date(year,0,z0-6,1);
      if (srt.getDay()==day&&srt.getFullYear()<=year){
       date=(day==0?months[srt.getMonth()]:nu(srt.getDate()))+'-'+(day==0?nu(srt.getDate()):months[srt.getMonth()])+'-'+srt.getFullYear()+'\n';
       sel.options[sel.options.length]=new Option(date,date);
      }
     }
     sel.selectedIndex=0;
    }
    
    function nu(nu){
     return nu>9?nu:'0'+nu;
    }
    
    Weeks(2012,1,'tst');
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #6
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Yes dropdown list of week like Week1, Week2 etc based on the whole year then when I click week 1 in a textbox display the date range from that week.

    Thank you

  • #7
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by julianashull View Post
    Do you mean populate the list with every
    [img]http://www.****************/song3.jpg[/img][img]http://www.****************/song2.jpg[/img][img]http://www.****************/song4.jpg[/img]
    based on year

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by newphpcoder View Post
    Yes dropdown list of week like Week1, Week2 etc based on the whole year then when I click week 1 in a textbox display the date range from that week.

    Thank you
    When do you want the weeks to start - Saturday, Sunday, or Monday - different parts of the world use any of those three even though the days are named with Saturday first.

    Also which is the first week of the year - the first week with any days in the year, the first week with at least 4 days in the year or the first week with all days in the year.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    When do you want the weeks to start - Saturday, Sunday, or Monday - different parts of the world use any of those three even though the days are named with Saturday first.

    Also which is the first week of the year - the first week with any days in the year, the first week with at least 4 days in the year or the first week with all days in the year.
    I want week starts at monday and ends in sunday.

    Thank you

  • #10
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    here's one way...

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <select id="tst" size="1" onchange=document.getElementById("txt").value=this.value>
    <option> select a week </option>
    </select>
    <input type="text" id="txt" style="width:300px"/>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    var first = new Date("Jan 2 2012");
    var second= new Date("Jan 8 2012");
     for (i=1; i<54;i++){
     document.getElementById("tst").options[i]=new Option("week "+i,first.toDateString()+" - "+second.toDateString())
     first=new Date(first.setDate(first.getDate()+7));
     second=new Date(second.setDate(second.getDate()+7));
     }
     
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    Last edited by xelawho; 03-07-2012 at 07:37 AM.


  •  

    Posting Permissions

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