Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

[web] Is it possible to do this in javascript? or get all input objects on the page?

This topic is 4906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was wondering if it was possible to do something like this in javascript? eg: Say I have 3 textfields called obj1, obj2 and obj3. for(var i=1;i<4;i++) { //1 to 3 (obj+i).value = "whatever"; } Although this code doesn't work, is there someway to actually do it like so?, as I remember one of my college teachers showing me another students javascript code who had done something like that, but now I can't remember how. Or is there a way to get all input/text area objects in the page without specifying each of their names, eg automatically recall all the names? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Q Is it possible to do this in javascript?
A Yes. For all reasonable 'this'.

for(var i=1;i<4;i++) { //1 to 3
document.getElementByID["obj"+i].value = "whatever";
}

should work if I didn't overlook some typo

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!