...

View Full Version : Question about displaying weeks for the whole year in a drop down list



newphpcoder
03-05-2012, 09:23 AM
Hi..

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

Thank you

webdev1958
03-05-2012, 09:34 AM
what do you mean?

newphpcoder
03-05-2012, 09:36 AM
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

Philip M
03-05-2012, 10:34 AM
What do you mean by "week base"? Do you mean populate the list with every (say) Monday in the year? Or what?

vwphillips
03-05-2012, 01:32 PM
<!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>

newphpcoder
03-07-2012, 01:09 AM
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

newphpcoder
03-07-2012, 03:56 AM
Do you mean populate the list with every
http://www.****************/song3.jpghttp://www.****************/song2.jpghttp://www.****************/song4.jpg

based on year

felgall
03-07-2012, 06:22 AM
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.

newphpcoder
03-07-2012, 06:29 AM
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

xelawho
03-07-2012, 06:52 AM
here's one way...


<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum