/    Sign up×
Community /Pin to ProfileBookmark

Name of object

Hi guys,

I pass a combobox object to a function and in that function I need to get the name of the object ([B]How can I do that?[/B]) and compare it to a list of strings I already entered. Please give me an example to solve that.

Regards,

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@netbuddyJun 25.2006 — what is you code so far? please post it so people can help you.
Copy linkTweet thisAlerts:
@ba02000authorJun 28.2006 — hello again,

I just need to get an object(Text field, Textarea,,,etc) name in javascript code.

Regards,
Copy linkTweet thisAlerts:
@felgallJun 28.2006 — <textarea id="something"></textarea>

var textareaSomething = document.getElementById('something');

Just give each field you want to reference a unique id value (in place of 'something' in the above example) and use document.GetElementById to reference it.
Copy linkTweet thisAlerts:
@ba02000authorJun 28.2006 — thank you,,,,,

But I need the to get the name of an object, like:

<textarea id="thing" name="anotherthing"></textarea>

var objectName = .....;

What is the code that get me the name.

Regards,
Copy linkTweet thisAlerts:
@KorJun 28.2006 — Man, make yourself clear, otherwise I may think you try to solve a paradox. To refere an object by it's name, you must know it's name, but if you know it's name, why to search for it?

Now. Can you detail what you need? You want to refere the object with a given name or you want to find if there is an object which has the same name as a given string?

First case

var myObj = document.forms['formname'].elements['elementname']

Second case

var myString='foo';

var allElements=document.forms['formname'].elements

for(var i=0;i<allElements.length;i++){

if(allElements[i].name==myString){

... do something with the element allElements[i]....

}

}
×

Success!

Help @ba02000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...