• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute javascript from inner HTML

 
Felicita Nef
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use jQuery to perform your Ajax. It will automatically execute any script blocks included in loaded HTML fragments.
 
Felicita Nef
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic