Sign in to follow this  
johnnyBravo

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

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this