Hi everyone,
I’m very new to javascript and I’m working on a little project. Anyhow I can’t quite figure out if I can or how to loop this code to cut down on its size. Basically I have 16 select form objects on my html page all named length1, length2, length3 etc all the way to 16. When the body loads I have an onload fillCategory(). That function fills the selectbox with options. Anyhow I would I loop this so I don’t have to have 200 lines of code for each select box.
Here is my current code with a few of the options. Additionally, I can’t just name them all length1 or something because each 1 is used differently to add time.
Thanks in advance,
[CODE]function addOption(selectbox, value, text )
{
var optn = document.createElement(“OPTION”);
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
function fillCategory(){
// this function is used to fill the category list on load
addOption(document.time.length1, “0”, “0”, “”);
addOption(document.time.length1, “5”, “5”, “”);
addOption(document.time.length1, “6”, “6”, “”);
addOption(document.time.length1, “7”, “7”, “”);
addOption(document.time.length1, “8”, “8”, “”);
addOption(document.time.length1, “9”, “9”, “”);
addOption(document.time.length1, “10”, “10”, “”);
addOption(document.time.length1, “11”, “11”, “”);
addOption(document.time.length1, “12”, “12”, “”);
addOption(document.time.length1, “13”, “13”, “”);
addOption(document.time.length1, “14”, “14”, “”);
addOption(document.time.length1, “15”, “15”, “”);
addOption(document.time.length1, “20”, “20”, “”);
addOption(document.time.length1, “25”, “25”, “”);
addOption(document.time.length1, “30”, “30”, “”);
addOption(document.time.length2, “0”, “0”, “”);
addOption(document.time.length2, “5”, “5”, “”);
addOption(document.time.length2, “6”, “6”, “”);
addOption(document.time.length2, “7”, “7”, “”);
addOption(document.time.length2, “8”, “8”, “”);
addOption(document.time.length2, “9”, “9”, “”);
addOption(document.time.length2, “10”, “10”, “”);
addOption(document.time.length2, “11”, “11”, “”);
addOption(document.time.length2, “12”, “12”, “”);
addOption(document.time.length2, “13”, “13”, “”);
addOption(document.time.length2, “14”, “14”, “”);
addOption(document.time.length2, “15”, “15”, “”);
addOption(document.time.length2, “20”, “20”, “”);
addOption(document.time.length2, “25”, “25”, “”);
addOption(document.time.length2, “30”, “30”, “”);
addOption(document.time.length3, “0”, “0”, “”);
addOption(document.time.length3, “5”, “5”, “”);
addOption(document.time.length3, “6”, “6”, “”);
addOption(document.time.length3, “7”, “7”, “”);
addOption(document.time.length3, “8”, “8”, “”);
addOption(document.time.length3, “9”, “9”, “”);
addOption(document.time.length3, “10”, “10”, “”);
addOption(document.time.length3, “11”, “11”, “”);
addOption(document.time.length3, “12”, “12”, “”);
addOption(document.time.length3, “13”, “13”, “”);
addOption(document.time.length3, “14”, “14”, “”);
addOption(document.time.length3, “15”, “15”, “”);
addOption(document.time.length3, “20”, “20”, “”);
addOption(document.time.length3, “25”, “25”, “”);
addOption(document.time.length3, “30”, “30”, “”);
}