Click to See Complete Forum and Search --> : Javascript Arrays


deanoid
06-04-2003, 10:51 AM
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>

AdamGundry
06-04-2003, 11:02 AM
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

deanoid
06-04-2003, 11:17 AM
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