Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerHTML onclick() functionality

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
0
0
US
I have a web page with a <DIV> set up to receive an 'external' HTML page and display it.
The 'Child' HTML page content is loaded into the <DIV>'s innerHTML to be displayed.
Think of this as the 'Parent' page displaying the 'Child' page within the specified <DIV>
In general this is working fine.

But I also have a Search function which searches the text within these 'external' HTML pages to see if it can find a file which contains the text.
When/If one or more 'external' documents are found a new SearchResults.htm web page is created and loaded into the <DIV>'s innerHTML - thereby displaying the findings (think of a Google search findings).
These findings are listed as links - each with its own onclick() defined.

'Child' Page Link Example:
<a href = "#" onclick = "DisplayDocument('1-Disposition-4-Generate Single Letter.htm')" href = "#">Disposition-Generate Single Letter</a>

Within the 'Parent' page I have the link's associated Javascript function ( DisplayDocument() ) which is supposed to execute when a 'Child' page link is clicked.

But it seems as though the 'Child' page onclick()'s cannot find the js function residing in the 'Parent' page.
It seems as though it is trying to find the js function within the 'Child' page instead of within the 'Parent' page.

Is this 'normal' and how can it be resolved?

Thanks,
JRB-Bldr



 
But it seems as though the 'Child' page onclick()'s cannot find the js function residing in the 'Parent' page.

That's because it cannot, the inserted elements cannot reference the DOM of the parent because it is not part of it, the inserted scripts and the parent DOM do not 'know' each other exist.

ALSO having a '#' in the href means that EACH time that link is clicked it triggers a page reload.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Chris - thanks for the reply.

I did finally get things working.
It turns out that I was putting the 'external' HTML document into the <DIV> as an <object> rather than just putting its 'raw' HTML code.
Once I changed this things started working just fine.

Thanks,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top