Solved

How to get pointer to a DHTML created element in MSHTML???

Posted on 2004-10-03
7
259 Views
Last Modified: 2013-11-19
Hi,
I have a web page that creates an input box when clicked on the cell of a table. THe html is like this:

<table><tr><td><span id='mytag' onclick='myfunc(this')/>
</td></tr></table>

<script language='javasript'>
function myfunc(element)
{
    element.parentElement.innerHTML="<input id='mytag'></input>";
}


This creates the input element when I click on the span tag. Now what I want is to access this input element from MSHTML.
I have a window in which I have embedded a browser control. When I load the page in the browser, obviously  there is no input element, so I cant access it. But after I have clicked on the span tag, the input element is created. calling get_document->get_all->item("mytag"), doesnt return pointer to the DHTML created input element. I go on getting the pointer to the span tag.

What should I do to get pointer to the Input tag that got created as a result of onclick event??

Thanks in advance,
Sarah.
0
Comment
Question by:sarah81
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Havin_it
ID: 12215717
Not sure if this alone will solve your problem, but in your code above, the span and the dynamically-created input have the same ID. That's gonna cause problems...
0
 

Accepted Solution

by:
texascatch earned 50 total points
ID: 12294757
Sarah,

In effect, having duplicate id's will cause you problems. The id should be unique throughout the scope of the current document. If a document contains more than one object with the same identifier, the objects are exposed as a collection that can be referenced only in ordinal position.

Im enclosing your example with a few changes. When the page loads you will receive the span object. Once the input text is created click on it to get an alert message with the input object.

Hope this helps,
Texascatch

<html>
<body>
<table border=1 width=100%>
<tr>
<td><span style='border:1px solid red; width:100px; heigth:100px' id='mySpan' onclick='myfunc(this)'></span>
</td>
</tr>
</table>

<script>
function myfunc(element)
{
    element.parentElement.innerHTML="<input id='myInput' onclick='msg()'></input>";
}
alert(document.getElementById("mySpan").tagName);
function msg(){
alert(document.getElementById("myInput").tagName);
}
</script>
</html>
0
 
LVL 1

Author Comment

by:sarah81
ID: 12294855
no the problem here is that the HTML must have both span and input tags with the same name, else there is no way to recognize the new input box.

may be this wasnt the right place to post this question but i didnt find any topic area where i could post questions related to MSHTML.

and yeah u r right, 2 elements with same name can be accessed thru a collecton and thats what i have done.

so well my prob is solved. thanks for ur help anyways.

i cant give u all points for this, but i will give a few to texascatch if there is some way to give some points. is there?
0
 

Expert Comment

by:texascatch
ID: 12294889
http://www.experts-exchange.com/help.jsp#hi19
this talks about the points..im new here..thank you
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now