Jump to content


Photo

Setting Index On Drop Down Box


  • Please log in to reply
3 replies to this topic

#1 Michael

Michael
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 February 2006 - 08:12 AM

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.

#2 miksel

miksel
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 05 February 2006 - 03:23 PM

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

document.formTwo.publicSelection.selectedIndex=5;

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


/micke


#3 Michael

Michael
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 February 2006 - 04:07 PM

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.

#4 miksel

miksel
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 February 2006 - 11:28 PM

Ok, maybe this is what you're looking for..
function set_selection()
{
   box = document.all("publicSelection");
   for(x=0; x<box.length; x++)
   {
      box[x].selectedIndex=ary[x];
   }
}

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users