Current location: Hot Scripts Forums » General Web Coding » JavaScript » month drop down list


month drop down list

Reply
  #1 (permalink)  
Old 03-31-04, 01:39 AM
angela angela is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
month drop down list

Hello

i need some help here...i need a javascript to do a drop down list of months.

currently i hardcoded it in my program..

<select name="Mth" class="formlist">
<option></option>
<option value = "1">January</option>
<option value = "2">February</option>
<option value = "3">March</option>
<option value = "4">April</option>
<option value = "5">May</option>
<option value = "6">June</option>
<option value = "7">July</option>
<option value = "8">August</option>
<option value = "9">September</option>
<option value = "10">October</option>
<option value = "11">November</option>
<option value = "12">December</option>
</select>

BUT my lecturer discourages that...he requested that i do a javascript...i managed to find one...but it returns a string..
eg. if i select Jun...it returns jun...but i would like a 6 instead...
furthermore this script has some error...the drop down list shows 2 Mar and no Feb...

<script type="text/javascript">

function writeMonthOptions()
{
var theMonth;
var monthCounter;
var theDate = new Date();

for (monthCounter = 0; monthCounter < 12; monthCounter++)
{
theDate.setMonth(monthCounter);
theMonth = theDate.toString()
theMonth = theMonth.substr(4,3);
document.write('<OPTION value=' + theMonth + '>' + theMonth);
}
}

</script>

<select name="Mth" class="formlist">
<option></option>
<SCRIPT LANGUAGE=JavaScript>
writeMonthOptions();
</SCRIPT>
</select>

help please...thank u!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-31-04, 02:42 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

I have no idea why it returns two Mar since it grabs the info from the Date Object and never modifies it. (just cuts away some info using .substr())

However, to fix it you could do like this:

function writeMonthOptions()
{
var Months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec")

for (monthCounter = 0; monthCounter < Months.length; monthCounter++)
{
document.write('<OPTION value=' + (monthCounter+1) + '>' + Months[monthCounter]);
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-31-04, 03:33 AM
angela angela is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
thanks!!!!
i learn something!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down menu problem !!! nurqeen PHP 1 02-08-04 09:07 PM
dyanamic list box based on a variable solovaz JavaScript 0 01-16-04 04:02 AM
Important:50% off discount - web hosting from $2.08 / month and resellers from $9.95 HarveyHosting General Advertisements 0 01-02-04 07:24 PM
Tremendous Hosting Sale! Accounts from $2.95 and one month FREE! jmanns General Advertisements 0 11-05-03 08:40 AM


All times are GMT -5. The time now is 06:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.