Filling multiple drop boxes at once

F

Flic

Hi,

I made a page with two drop boxes in, with the aim of repeating a lot
of times. I set it up so that instead of repeating the options for
each box they would be filled in when the page was loaded. The two
boxes worked fine with that and a number of other functions they
performed but now I've come to duplicate them and I've hit a problem.

I have named each drop down box consecutively (sp?) and have a while
loop to fill them but its not working.

Please see the code below:

function load(){
var i = 0;
while (i <= 10) {
var selcat = ("category" + i);
var selpri = ("price" + i);
var selnam = ("name" + i);
document.order.selpri.value = "";
document.order.selcat[0] = new Option("Please select...", "cat",
true);
document.order.selcat[1] = new Option("Accessories", "acc", false);
document.order.selcat[2] = new Option("Bolted Silo", "bol", false);
document.order.selcat[3] = new Option("Welded Silo", "wel", false);
document.order.selcat[4] = new Option("Horizontal Silo", "hor",
false);
document.order.selnam[0] = new Option("Please select a category...",
"cat", false);
i++;
} }

Am I being really silly and missing something obvious? I tried using
getElementById but that didn't work, I'm thinking because technically
its not the id.

Any help would be much appreciated! Thanks
 
S

scripts.contact

I made a page with two drop boxes in, with the aim of repeating a lot
of times. I set it up so that instead of repeating the options for
each box they would be filled in when the page was loaded. The two
boxes worked fine with that and a number of other functions they
performed but now I've come to duplicate them and I've hit a problem.

I have named each drop down box consecutively (sp?) and have a while
loop to fill them but its not working.

add method of select element -
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/add.asp

--------untested-----
var selElement;
function load(){
var i = 0;
while (i <= 10) {
selElement=document.createElement("select")
addOption("text","value")
addOption("text","value")
document.body.appendChild(selElement)
i++
}
}

function addOption(t,v){
var oOption = document.createElement("OPTION");
selElement.options.add(oOption);
oOption.text=t; oOption.Value = v
}
 
F

Flic

add method of select element -http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/add...

--------untested-----
var selElement;
function load(){
var i = 0;
while (i <= 10) {
selElement=document.createElement("select")
addOption("text","value")
addOption("text","value")
document.body.appendChild(selElement)
i++

}
}

function addOption(t,v){
var oOption = document.createElement("OPTION");
selElement.options.add(oOption);
oOption.text=t; oOption.Value = v



}- Hide quoted text -

- Show quoted text -

The code I have works adding elements as I made it work for a single
one before expanding it. It just doesn't work in the loop, and thats
what I want help with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top