Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/5954-variable-object-property-names/
Share on other sites

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

[code]alert(document.getElementById('select1').value)[/code]
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 :)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.