Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-12-04
4
Medium Priority
?
2,920 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 150 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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.
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…

722 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