• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Inner HTML not running JavaScript

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i have this script running (which works perfect) The REL attribute is linked to a Jquery plugin called Shadow box that is the only thing I need to get working. Currently it seems that Javascript is not even running within the innerhtml.




Then it displays the page on the side of my other page perfectly. Now the problem I am having is i need to run Javascript from that innerhtml ,

My Innerhtml is

Any Ideas why my page is not loading JavaScript?

I appreciate any help in advance!
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just shoving script into innerHTML isn't going to make it run.

You say you are using jQuery, so why aren't you using it to do your Ajax? jQuery will cause the script to execute when loaded with the .load() method.
 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jquery loads when you click on the link. Not when the page is loaded . Not sure if that helps you undestand what im doing ?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
putting JavaScript on the page with innerHTML is not going to run. The browser does not evaluate it.

Libraries like jQuery pull out the scripts and eval() it.

Eric
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Not sure if that helps you undestand what im doing ?

Then let me summate: you are loading some HTML and script, generated by PHP, from the server via Ajax. The script in this loaded block is not executing when you insert the block into the DOM using innerHTML.

Is that correct?

If so, my reply stands.

[As does Eric's which says the exact same thing I said.]
 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! I understand now, And i am unsure how to change from ajax to jquery simply. It sounds almost a hassle but I guess i have the itme ill switch over.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Loading an element with jQuery:

Doesn't seem like rocket science to me!
 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI,
This worked inside the innerHTML


<img style="cursor:pointer" src="<?php echo $this->url('images/layout3/icons/icon-bandwidth.gif')?>" onclick="Shadowbox.open({ content:'<?php echo $this->url("networktools/".$c->ip."/bandwidthgraph");?>', width:'750',height:'580', player:'iframe'}); return false;" >
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, there's no script block in that.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic