Michael Posted February 5, 2006 Share Posted February 5, 2006 HelloI 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. Quote Link to comment https://forums.phpfreaks.com/topic/3323-setting-index-on-drop-down-box/ Share on other sites More sharing options...
miksel Posted February 5, 2006 Share Posted February 5, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/3323-setting-index-on-drop-down-box/#findComment-11341 Share on other sites More sharing options...
Michael Posted February 5, 2006 Author Share Posted February 5, 2006 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 isdocument.formTwo.publicSelection[i].selectedIndex=something[j];which is the reason for the loop.Unfortunately I cannot get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/3323-setting-index-on-drop-down-box/#findComment-11342 Share on other sites More sharing options...
miksel Posted February 6, 2006 Share Posted February 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/3323-setting-index-on-drop-down-box/#findComment-11397 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.