By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,467 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,467 IT Pros & Developers. It's quick & easy.

Access Document Objects that have no Name or ID Attribute

P: 2
Hey All,

I am using ADF UIX, which is a Oracle Framework to develop a web application. It is based off XML and translates the XML to HTML upon execution. The problem I'm having is it is creating some anchors I need to access in JavaScript without a name or ID attribute. There is also no way in the XML i can assign these objects a name or ID.

For example, I have this <dateField> xml tag I create. This renders on the HTML page as a input field and a calendar image with an anchor that has an onlick attribute that spawns a pop-up date picker. I need to access the anchor for that date picker, but UIX does not render the anchor tag with an ID or with a name.

How can I access such elements in JavaScript? Is there some way to get an array of ALL objects in the document, even if they DO NOT have an ID? I tried document.anchors[], but it will not work if the anchor does not have a name or id. Any ideas?

Thanks.
Nov 14 '06 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 392
The problem I'm having is it is creating some anchors I need to access in JavaScript without a name or ID attribute. There is also no way in the XML i can assign these objects a name or ID.
That may not be true. If you can access or modify the XSL that is doing the XML to HTML translation then you can make it do anything you want..... well most things.

For example, I have this <dateField> xml tag I create. This renders on the HTML page as a input field and a calendar image with an anchor that has an onlick attribute that spawns a pop-up date picker. I need to access the anchor for that date picker, but UIX does not render the anchor tag with an ID or with a name.
What is it you need to access the A tag for? i.e. What change do you need to make? Replacing the A tag with a SPAN tag, and setting the onclick, onmouseover, etc events might give you what you need.

You can access the A tab manually thought the HTML tag hierarchy, but it is really annoying to do and is easily broken by changes in the HTML. To do this you would need to do something like document.body.<<some tag>>.<<some tag>>.<<some tag>>.<<A tag>>. Or if the A tag is a child of a tag you can identify you could do something like document.getElementById('<<Id of known parent tag>>').childNodes(); and then loop though the array returned to try and find the tag you need.

Is there some way to get an array of ALL objects in the document, even if they DO NOT have an ID?
Well you could do something like document.body.getElementsByTagName('A'); I am not sure if that would be recursive and read the entire page, or just read one level.

The other option would be document.body.childNodes which would return an array of the tags under the body tag, and then you would need to recursively read though each node of that array for their child nodes over and over until you read though all of the tags on the page.
Nov 14 '06 #2

P: 2
pronerd,

I needed to access the anchor tag because I need to change the onclick property. UIX renders the anchor with an onclick that spawns a pop-up date picker. I only wanted to the user to be able to open the date picker pop-up if another field on the page was empty. There is a search field that could be used that will return only one hit, and if they use that search field, the calendar pop-up should not be available to them. So I wanted it to erase the onclick if anything was typed into that search field. And if the field was emptied, I would re-populate the correct onclick call for the date picker to be spawned.

Your solution was right on track. I ended up using
document.getElementsByTagName('a'); which returned an array of all anchor tags on the page. I then just found the correct index I needed and I was able to get it to set the onclick property to null or the correct function based on when the aforementioned search field was changed and if it had data in it or not.

Thanks for your help!
Nov 14 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.