Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2005, 09:10 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default Array change 06 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.....
Code:
slice_mm

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old June 7th, 2005, 11:50 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Something like:

<html>
<head></head>
<body>

<b>Expect: Jan, Dec</b>
<br />

<script>

// months to test this works!
var testMonthJan='01';
var testMonthDec='12';

// array of month names, numbered 1..12 - zero is empty string
var months = new Array('','Jan','Feb','Mar','Apr','May','Jun','Jul' ,'Aug','Sep','Oct','Nov','Dec');

document.write("--&gt; ");
printMonth(testMonthJan);
document.write(", ");
printMonth(testMonthDec);

// print the name of our month
function printMonth(inp) {
    var stripZero = inp.replace(/^0/,""); //strip leading zero
    if (stripZero<1 || stripZero>12) {
        // check we have a valid month!
        document.write("Invalid month given to printMonth: " + inp);
    }
    else {
        // print month name if we do
        document.write(months[stripZero]);
    }
}

</script>

</body>
</html>

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 06 - Blog: Error with connection strings danielson BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 March 13th, 2007 09:29 AM
Chapter 06 cardme42 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 December 24th, 2004 08:17 PM
Beginning Visual C# Exercises - Chapter 06 seblake C# 1 July 19th, 2004 09:15 AM
change order of an array automatically after add SauSaigon Beginning PHP 7 February 22nd, 2004 12:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.