Solved

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

Posted on 2004-10-03
7
261 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

825 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