473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Execute JavaScript from innerHTML

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 :
Expand|Select|Wrap|Line Numbers
  1. ... 
  2. <script type="text/javascript"> 
  3. function getXMLHTTP() { //fuction to return the xml http object 
  4.         var xmlhttp=false;     
  5.         try{ 
  6.             xmlhttp=new XMLHttpRequest(); 
  7.         } 
  8.         catch(e)    {         
  9.             try{             
  10.                 xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); 
  11.             } 
  12.             catch(e){ 
  13.                 try{ 
  14.                 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
  15.                 } 
  16.                 catch(e1){ 
  17.                     xmlhttp=false; 
  18.                 } 
  19.             } 
  20.         } 
  21.  
  22.         return xmlhttp; 
  23.     } 
  24.  
  25.  
  26.  
  27.     function getSchool(strURL) {         
  28.  
  29.         var req = getXMLHTTP(); 
  30.  
  31.         if (req) { 
  32.  
  33.             req.onreadystatechange = function() { 
  34.                 if (req.readyState == 4) { 
  35.                     // only if "OK" 
  36.  
  37.                     if (req.status == 200) {                         
  38.                         document.getElementById('schooldiv').innerHTML=req.responseText; 
  39.                     } else { 
  40.                         alert("There was a problem while using XMLHTTP:\n" + req.statusText); 
  41.                     } 
  42.                 }                 
  43.             }             
  44.             req.open("GET", strURL, true); 
  45.             req.send(null); 
  46.         } 
  47.  
  48.     } 
  49. </script> 
  50.  
  51. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/jquery.multiselect.css" /> 
  52. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/style.css" /> 
  53. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/prettify.css" /> 
  54. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/jquery-ui.css" /> 
  55. <script type="text/javascript" src="../jquery_selectes/scripts/jquery.js"></script> 
  56. <script type="text/javascript" src="../jquery/scripts/jquery-ui.min.js"></script> 
  57. <script type="text/javascript" src="../jquery_selects/assets/prettify.js"></script> 
  58. <script type="text/javascript" src="../jquery_selects/scripts/jquery.multiselect.js"></script> 
  59. <script type="text/javascript"> 
  60. $(function(){ 
  61.     $("select#school").multiselect({ 
  62.         selectedList: 0 
  63.     }); 
  64. }); 
  65. </script> 
  66. <script type="text/javascript"> 
  67. $(function(){ 
  68.  
  69.     $("select#uni").multiselect({ 
  70.         multiple: false, 
  71.         header: "Επιλέξτε", 
  72.         noneSelectedText: "Επιλέξτε", 
  73.         selectedList: 0 
  74.     }); 
  75.  
  76. }); 
  77. </script> 
  78. ... 
  79. <body> 
  80. ... 
  81. <div class="announcement_borderless" style="border-top-left-radius:10px; border-top-right-radius:10px; border-bottom-left-radius:10px; border-bottom-right-radius:10px;"> 
  82.  
  83.        <p> 
  84.       <select title="Basic example" name="example-basic" size="5"  style="font-size:12px; width:250px" id="uni" onChange="getSchool('findschool.php?uni='+this.value)"> 
  85.     <option value="1">ΕΜΠ</option> 
  86.     <option value="2">ΑΠΔ</option> 
  87.     <option value="3">Γ</option> 
  88.     <option value="4">Δ</option> 
  89.     <option value="5">Ε</option> 
  90.     <option value="6">Ζ</option> 
  91.     <option value="7">Η</option> 
  92.     <option value="8">Θ</option> 
  93.     <option value="9">Η</option> 
  94.     <option value="10">Ι</option> 
  95.     <option value="11">Κ</option> 
  96.     <option value="12">Λ</option> 
  97.     </select> 
  98.     </p> 
  99.     <?php 
  100.     include $_SERVER['DOCUMENT_ROOT']."jquery_selects/createschool.php"; 
  101.     ?> 
  102.     <div id="schooldiv"> 
  103.  
  104.     <select id="school" multiple="multiple" name="example-basic" size="5" style="font-size:12px; width:250px" > 
  105.         <option value="option1">Nefeli</option> 
  106.         <option value="option2">Pavlos</option> 
  107.         <option value="option3">Orestis</option> 
  108.         <option value="option4">Maria</option> 
  109.         <option value="option5">Panagiotis</option> 
  110.         <option value="option6">Fotini</option> 
  111.         <option value="option7">Kostas</option> 
  112.         </select> 
  113.  
  114.     </div> 
  115.     </div> 
  116. ... 
  117. </body> 
  118. ...

findschool.php :

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. ?> 
  4. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/jquery.multiselect.css" /> 
  5. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/style.css" /> 
  6. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/prettify.css" /> 
  7. <link rel="stylesheet" type="text/css" href="../jquery_selects/assets/jquery-ui.css" /> 
  8. <script type="text/javascript" src="../jquery_selectes/scripts/jquery.js"></script> 
  9. <script type="text/javascript" src="../jquery/scripts/jquery-ui.min.js"></script> 
  10. <script type="text/javascript" src="../jquery_selects/assets/prettify.js"></script> 
  11. <script type="text/javascript" src="../jquery_selects/scripts/jquery.multiselect.js"></script> 
  12. <script type="text/javascript"> 
  13. $(function(){ 
  14.     $("select#school").multiselect({ 
  15.         selectedList: 0 
  16.     }); 
  17. }); 
  18. </script> 
  19.  
  20.  
  21. <select id="school" multiple="multiple" name="example-basic" size="5" style="font-size:12px; width:250px" > 
  22.         <option value="option1">eleni</option> 
  23.         <option value="option2">katerina</option> 
  24.         <option value="option3">eutuxia</option> 
  25.         </select> 
  26.         <?php 
  27.  
  28. ?>
  29.  
Any help would be valuable. Thanks in advance.
May 16 '12 #1
1 2761
Dormilich
8,658 Expert Mod 8TB
why not just replace the options instead of the full select? this way you don’t delete the handlers set on the select.
May 17 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: nerf | last post by:
How can I execute a javascript file(test.js) from within PHP. I'm running oscommerce and want to insert a menu created in javascript by Sothink DHTMLMenu. Thanks in advance
1
by: oleg_orel | last post by:
I need to access web sites using my scripts written in Perl. I use lynx and elinks to access web pages. It works fine, unless the pages has some Javascript code. Most Javascript stuff is working...
3
by: moondaddy | last post by:
I have a frame set where I have a hidden frame page used to marshal data back and forth. In another frame who's source page needs to stay fixed and not do round trips. However, at times I want do...
1
by: Peter Dickson | last post by:
I am trying to pull data from a website into a database. Part of the website I am getting the data uses javascript to display the data. The only variable being passed to the javascript when it...
13
by: UnaCoder | last post by:
Hi, I'm trying to use client side JavaScript from an HTML file to open and make changes to an Excel SpreadSheet using ADO w/ ODBC. What a pain it is to do this. Anyways, I am able to open the...
6
by: dark.peony | last post by:
Hi, (--1--) I'm trying to find a way to jump to a link (<a href="ref"></a>) in a page that is generated with javascript. The source view of the page only shows the javascript methods. The...
1
by: rajasekar.karthik | last post by:
In inner html we are using a javascript function i want to now how to call this function. <div style='padding-left:130px;' id='bowling'> </div> <div...
11
by: Hakan ÖRNEK | last post by:
Hi , I register client scripts like this; -------------------------------------------------------------------------- ----------- Public Sub CreateClientAlert(ByVal Message As String, ByVal...
9
by: Cogito | last post by:
My program builds several tables using inner HTML. All the tables are displayed only when the program terminates. How can I make it display one table at a time and then wait for a click before...
7
by: Peter | last post by:
I have a HoverMenuExtender which contains an asp:PlaceHolder, this place holder has a User Control and this control contrains a Button. The problem I am having is after the button fires the click...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.