array of HTML objects ?

Results 1 to 2 of 2

Thread: array of HTML objects ?

  1. #1
    Join Date
    Dec 1969

    Default array of HTML objects ?

    Hi,<BR><BR>I&#039m creating a page that has a bunch of dynamic, dependant dropdown menus. (You may remember me from yesterday.) Well, I have a script which I think will do the trick, but now my problem is that I need a way to call the specific object in the script. For example, all of the examples I have seen are something like this...<BR><BR>document.form.selectmenu.selectedIn dex<BR><BR>But, I have a whole page of these, so I need a way to have it call the appropriate one...<BR><BR>document.form.selectmenu_1.selectedI ndex<BR>-or-<BR>document.form.selectmenu_2.selectedIndex<BR><B R>There is no set number of these... it depends on input from the previous page. Is it possible to maybe use an array of these selectmenu objects and use something like this? :<BR><BR>document.form.selectmenu_array[i].selectedIndex<BR><BR>thanks in advance,<BR><BR>Casey

  2. #2
    Join Date
    Dec 1969

    Default Could do it, but maybe better...

    You could use an array, might even be more efficient, but if they are all regularly numbered as you show, then you could also use the JavaScript "eval" function.<BR><BR>Something like this:<BR><BR>for( i = 1; i &#060;= maxSelectListNumber; ++i )<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;curSelect = eval( "document.TheForm.selectmenu_" + i );<BR>&nbsp;&nbsp;&nbsp;&nbsp;curIX = curSelect.selectedIndex;<BR>&nbsp;&nbsp;&nbsp;&nbs p;curOpt = curSelect.options[curIX];<BR>&nbsp;&nbsp;&nbsp;&nbsp;alert( "For " + +", the selected option
    " <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;+ "has value " + curOpt.value + " and text " + curOpt.text );<BR>}<BR><BR>As you can see, if you do it "right" you can get away with only one call to "eval" (which is, admittedly, a tiny bit expensive...but what the heck this is on the user&#039s machine!) for each SELECT that you need to process.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts