Jump to content


Photo

Variable Object Property Names


  • Please log in to reply
1 reply to this topic

#1 jmturner

jmturner
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 27 March 2006 - 07:59 PM

Forgive my ignorance, I am new to JS and I am trying to learn how to allow an Object Property Name to be modified by using a variable, but I am unsure if this is a) possible; and b) what the correct way to do it would be.

Say you have:

document.form1.select1.value = 10;

What I want to be able to do is have "select1" be a variable so I can loop through many instances of this in a script.

Any help would be greatly appreciated!
John


#2 Guest_neewah_*

Guest_neewah_*
  • Guests

Posted 28 March 2006 - 05:36 PM

Hi, it is possible by using getElementById("[object]"), for example:

alert(document.getElementById('select1').value)
Would give you the value of the select1 object (notice you don't need to include form1).

You could then change 'select1' - it will allow you to use it as a variable with the getElementById javascript function. Hope that helps :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users