Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-03
7
Medium Priority
?
267 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
4 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 150 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

783 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