Refering to an object through a variable

Results 1 to 2 of 2

Thread: Refering to an object through a variable

  1. #1
    Ben Verwey Guest

    Default Refering to an object through a variable

    I have a function that changes the contents of a listbox by using it&#039s methods such as...<BR> <BR>document.MainForm.Step2.options[0]= new Option("Nothing Available");<BR><BR>That works fine, but only for that specific list box (i.e. Step2)<BR>I want to be able to pass in the name of any listbox that I want to change and store it&#039s name in a variable of some sort. Then I could use that variable in place of "Step2" I have tried creating a new object varible and using that, but it doesn&#039t seem to work. When I put the object variable in place of "Step2" in that line of code it doesn&#039t recognize it as an object.<BR><BR>It it possible to do what I want to do?<BR><BR>Ben

  2. #2
    Bruno Santos Guest

    Default RE: Refering to an object through a variable

    hi Ben,<BR><BR>i guess it is possible.<BR><BR><BR>&#060;script language=javascript&#062;<BR>function AddListItem(formname, listname, itemtext, itemvalue)<BR>{<BR>&nbsp;&nbsp;&nbsp;var myoption=document.createElement("OPTION");<BR>&nbs p;&nbsp;&nbsp;myoption.text=itemtext;<BR>&nbsp;&nb sp;&nbsp;myoption.value=itemvalue;<BR>&nbsp;&nbsp; &nbsp;if (formname==null &#124&#124 formname=="")<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;document.all.item(listna me).add(myoption);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp ;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.forms.item( formname).all.item(listname).add(myoption);<BR>&nb sp;&nbsp;&nbsp;};<BR>}<BR>&#060;/script&#062;<BR><BR><BR>Bruno (

Posting Permissions

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