×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

innerHTML onclick() functionality

innerHTML onclick() functionality

innerHTML onclick() functionality

(OP)
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



RE: innerHTML onclick() functionality

Quote:

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.

RE: innerHTML onclick() functionality

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close