SuperSal
Programmer
- Mar 13, 2007
- 33
Hi everyone, I have written some code to get the values from an array to populate a combobox(with help from monksnake)
The code works, however it puts all the array values in for each list. eg like below
High 2, High 3, High 4, High 5
High 2, High 3, High 4, High 5
High 2, High 3, High 4, High 5
High 2, High 3, High 4, High 5 .....etc
rather than
High 2
High 3
High 4
High 5 ....etc
I have tried playing around with the code but have been unsuccessful.
The code is as follows:
<BODY onLoad="addOption()";>
var Quality = new Array("High 2", "High 3", "High 4", "High 5", "High 6", "High 7", "High 8", "High 9", "High 10", "High 11", "Med 12", "Med 13", "Med 14", "Med 15", "Med 16", "Med 17", "Med 18", "Med 19", "Med 20", "Med 21" , "Low 22" , "Low 23" , "Low 24" , "Low 25" , "Low 26" , "Low 27" , "Low 28" , "Low 29" , "Low 30" , "Low 31")
function addOption(selectBox,resArrayLength)
{
var selectBox = document.getElementById("MHighQty");
selectBox.options.length = 0;
for (a = 0; a < Quality.length; a++) {
selectBox.options[a] = new Option(Quality, a);
}
}
<select name="MHighQty" id="MHighQty"><option></option></select>';
Is there anything that you can see which makes all the values from the array appear for each selection in the combobox.
Thanks
Sally
The code works, however it puts all the array values in for each list. eg like below
High 2, High 3, High 4, High 5
High 2, High 3, High 4, High 5
High 2, High 3, High 4, High 5
High 2, High 3, High 4, High 5 .....etc
rather than
High 2
High 3
High 4
High 5 ....etc
I have tried playing around with the code but have been unsuccessful.
The code is as follows:
<BODY onLoad="addOption()";>
var Quality = new Array("High 2", "High 3", "High 4", "High 5", "High 6", "High 7", "High 8", "High 9", "High 10", "High 11", "Med 12", "Med 13", "Med 14", "Med 15", "Med 16", "Med 17", "Med 18", "Med 19", "Med 20", "Med 21" , "Low 22" , "Low 23" , "Low 24" , "Low 25" , "Low 26" , "Low 27" , "Low 28" , "Low 29" , "Low 30" , "Low 31")
function addOption(selectBox,resArrayLength)
{
var selectBox = document.getElementById("MHighQty");
selectBox.options.length = 0;
for (a = 0; a < Quality.length; a++) {
selectBox.options[a] = new Option(Quality, a);
}
}
<select name="MHighQty" id="MHighQty"><option></option></select>';
Is there anything that you can see which makes all the values from the array appear for each selection in the combobox.
Thanks
Sally