By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Filling multiple drop boxes at once

P: n/a
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

Mar 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Mar 7, 10:53 am, "Flic" <Felici...@gmail.comwrote:
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/a...ethods/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
}

Mar 7 '07 #2

P: n/a
On Mar 7, 5:34 pm, scripts.cont...@gmail.com wrote:
On Mar 7, 10:53 am, "Flic" <Felici...@gmail.comwrote:
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...

--------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.

Mar 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.