www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript Arrays

  1. #1
    Join Date
    May 2003
    Location
    london
    Posts
    2

    Post Javascript Arrays

    Hi, I would like to know how i can change the numeric values within this array to letters. If I change the numbers the letters the script does not work?

    Is this possible?

    Many thanks,

    Dean

    <script>
    <!-- Begin
    team = new Array(
    new Array(
    new Array("Holiday (H)",4122),
    new Array("Training (T)",2),
    new Array("Illness (I)",3),
    new Array("Business (B)",4),
    new Array("Authorised (A)",5)
    ),
    new Array(
    new Array("Vacation (V)",6),
    new Array("Sick (S)",7),
    new Array("Jury Duty (J)",8),
    new Array("Personal (P)",9),
    new Array("Floater (F)",0),
    new Array("Bereavement (B)",4),
    new Array("Leave without Pay (L)",6),
    new Array("Other (O)",3)
    )
    );
    function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
    var i, j;
    var prompt;
    // empty existing items
    for (i = selectCtrl.options.length; i >= 0; i--) {
    selectCtrl.options[i] = null;
    }
    prompt = (itemArray != null) ? goodPrompt : badPrompt;
    if (prompt == null) {
    j = 0;
    }
    else {
    selectCtrl.options[0] = new Option(prompt);
    j = 1;
    }
    if (itemArray != null) {
    // add new items
    for (i = 0; i < itemArray.length; i++) {
    selectCtrl.options[j] = new Option(itemArray[i][0]);
    if (itemArray[i][1] != null) {
    selectCtrl.options[j].value = itemArray[i][1];
    }
    j++;
    }
    // select first item (prompt) for sub list
    selectCtrl.options[0].selected = true;
    }
    }
    // End -->
    -->
    </script>

  2. #2
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    Did you put quotes around the letters when you used them in place of the numbers? I can't see any reason for this not working.

    Adam

  3. #3
    Join Date
    May 2003
    Location
    london
    Posts
    2
    I tried the following and it seems to work...

    <!-- Begin
    team = new Array(
    new Array(
    new Array("Holiday (H)", 'LETTERS'),

    thanks for taking the time to look at this for me..

    much appreciated!

    dean

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles