Solved

I have the object name - how do I get the object

Posted on 2003-12-04
4
2,918 Views
Last Modified: 2007-12-19
I have the name of the object that I want (and I have it stored as a string). How do I get the object that it refers to?

eg I have the string 'document.all.clResult1.style.visibility'
how do I get hold of the object so I can set one of it's properties?

My actual problem is, I need to call document.all.clResultXX.style.visibility = "visible"; - where XX is any number at all that is passed into the function. I've tried document.all.clResult+ XX +.style.visibility = "visible"; but that gives me a javascript error.

Is there a 'getObjectByName' funtion or anything like that?
0
Comment
Question by:mailBoy2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:mrh30
ID: 9874154
Providing your element has been correctly given an 'id', not a 'name', you can use document.getElementById('...') to fetch the element.
0
 
LVL 10

Accepted Solution

by:
Nushi earned 50 total points
ID: 9874166
hi there.

i missing some information.
there is a method getElementsByName(...) => return array of all elements with this name.

in your case it should be getElementsByNames( 'clResult1')[0].style.visibility.propertyName
or use document.getElementById('id') which return the Object.

do:
document.getElementById( clResult+XX).style.visibility

but you should have id to teh field.

if its in a form you can use:
document.form_name[clResult+XX].style.visibility

Nushi.

0
 
LVL 10

Expert Comment

by:Nushi
ID: 9874176
ot be more specific:

document.all => Ie syntax.
document.getElementById => DOM - return object
document.getElementsByName => DOM - return array of all objects with this name

Nushi.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9874203
document.getElementById('name') will work with names also but is ns6 and ie5+ only

you can also use (if you have a form on the page) which is ns4+ and ie5+ compatible

document.forms[0].elements['name']

0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question