aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Execute javascript from inner HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Execute javascript from inner HTML" Watch "Execute javascript from inner HTML" New topic
Author

Execute javascript from inner HTML

Felicita Nef
Greenhorn

Joined: May 16, 2012
Posts: 2
I am a newbie in javascript/ajax and I need some help.

I have 2 dropdown lists that the second one(id=school) depends on the first one(id=uni). On change of the 1st, a javascript function is called and via an innerHTML, the 2nd ddlist is updated with the right options.

Furthermore, my ddlists are decorated using some js and css. But, when the innerHMTL is called, the styling is lost since the javascript function in not called. My code is given below:

index.php


findschool.php


Any help would be valuable. Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Use jQuery to perform your Ajax. It will automatically execute any script blocks included in loaded HTML fragments.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Felicita Nef
Greenhorn

Joined: May 16, 2012
Posts: 2
Bear Bibeault wrote:Use jQuery to perform your Ajax. It will automatically execute any script blocks included in loaded HTML fragments.


Thanks for your reply but, could you be more specific and give me an example based on the code given, since I said before, I am a newbie...
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Felicita Nef wrote:
Bear Bibeault wrote:Use jQuery to perform your Ajax. It will automatically execute any script blocks included in loaded HTML fragments.


Thanks for your reply but, could you be more specific and give me an example based on the code given, since I said before, I am a newbie...


Search for the tutorial on Google. You will get many. If you face any issues then come back to us.


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Let's say that you want to inject an HTML fragment returned from an Ajax response into an element with the id of fred:

That's it. That's how easy Ajax is with jQuery. And if there are any script blocks embedded in the returned HTML fragment, they will be executed.

Simply include jQuery in your page and off you go!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Execute javascript from inner HTML