Solved

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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)

756 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