Jump to content

Archived

This topic is now archived and is closed to further replies.

Michael

Setting Index On Drop Down Box

Recommended Posts

Hello

I am trying to set the index on a drop down selection box. Tgis would be a trivial thing if I could use getElemenById. Unfortunately I have a set a selection boxes that i created using the phpbb engine and I can see no way of adding a numerical tag or something to make the id unique.

I have been trying to use something like

//set image drop down menu box indicies
for (i=0; i<(descriptionText.length); i++)
{
document.formTwo.publicSelection[i].selectedIndex = 5;
}

I have a 5 because I have been having a heck of time extracting a value from an array and also it does not seem work reliably. I know it should either work or not but sometimes it dowes and sometimes it does not. I have been fighting this problem for over 24 hours now and am really getting frustrted and punch.

I would appreciate it if anyone could help me out with this one. This is a show stopper for aprogram that shoud have take a few hiours to write.

Thanks.

Share this post


Link to post
Share on other sites
Hi,
I asume that you have a form named "formTwo" and a selectbox named "publicSelection".
You don't have to loop the options.. just replace the loop with this

[b]document.formTwo.publicSelection.selectedIndex=5;[/b]

The index start counting at 0, so a 5 will select the 6th option....


/micke

Share this post


Link to post
Share on other sites
Yes I have the form, and the selection box bu those names and I understand that I do not have to loop for a "5".

The number of selection boxes is unknown ahead of time so what I really have is

document.formTwo.publicSelection[i].selectedIndex=something[j];

which is the reason for the loop.

Unfortunately I cannot get it to work.

Share this post


Link to post
Share on other sites
Ok, maybe this is what you're looking for..
[code]
function set_selection()
{
   box = document.all("publicSelection");
   for(x=0; x<box.length; x++)
   {
      box[x].selectedIndex=ary[x];
   }
}
[/code]

it works for an unknown number of selectboxes as long as they are all named "publicSelection",
and the array (ary[]) got a value.
I'm sure you can modify it to meet your needs..

I've tested it in IE and FireFox.

/micke

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.