Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 7th, 2005, 9:12 AM   #1
crmpicco
Newbie
 
Join Date: Feb 2005
Posts: 13
Rep Power: 0 crmpicco is on a distinguished road
Question if it is 06 then change to JUN

How do i replace this Javascript variable with 'JAN', 'FEB', 'MAR' etc...

depending on what number the variable is e.g.

if it is 06 then change to JUN

example values are
01
02
03
04
05
06
07
etc.....
slice_mm
crmpicco is offline   Reply With Quote
Old Jun 7th, 2005, 9:49 AM   #2
kirkl_uk
Programmer
 
kirkl_uk's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 86
Rep Power: 4 kirkl_uk is on a distinguished road
Send a message via MSN to kirkl_uk
I would create a text array of the month codes:

var aMonths = new Array(12) { "JAN, "FEB", ..., "DEC" };

I doubt if that syntax works in javascript, but you should get the idea.

Then, to assign it, simply use something like:

slice_mm = aMonths[chosenMonth - 1];

Where chosenMonth is the numeric representation of the day, such as 6 for June.

Another way would be:

switch(chosenMonth) {
  case 1:
    slice_mm = "JAN";
    break;

  case 2:
    slice_mm = "FEB";
    break;

  ...

  case 12:
    slice_mm = "DEC";
    break;
}

But I prefer the first approach, personally.
__________________
kirkl_uk

Last edited by kirkl_uk; Jun 7th, 2005 at 9:55 AM.
kirkl_uk is offline   Reply With Quote
Old Jun 16th, 2005, 10:43 AM   #3
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
kirkl_uk is right, FYI the exact syntax for creating the array is:

var months=new Array("Jan","Feb", ...,"Dec");

cheers
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC