javascript - Populate multiple dropdown lists with PHP -


i have 3 dropdown lists populate sql database using php , javascript/ajax. first list starts filled options, second list populates database depending on selection. works fine , echo entire second list php. problem is: cant second drop down box repeat "onchange" function. tried many combinations no luck. second javasript function belong ? in html or php ? appreciated.

html first javascript function

<html> <head> <title>insert test</title>  <script> function getdate(str){     if (str==""){         document.getelementbyid("dateinput").innerhtml="";         return;     }      if (window.xmlhttprequest){// code ie7+, firefox, chrome, opera, safari         xmlhttp=new xmlhttprequest();     }     else{// code ie6, ie5         xmlhttp=new activexobject("microsoft.xmlhttp");     }     xmlhttp.onreadystatechange=function(){         if (xmlhttp.readystate==4 && xmlhttp.status==200){             document.getelementbyid("dateinput").innerhtml=xmlhttp.responsetext;         }     }     xmlhttp.open("get","test.php?q="+str,true);     xmlhttp.send(); } </script>   </head> <body> <form id="book" name="book" action="unfinished.php" method="post">   <p align="center">      <select name="cityinput" id="cityinput" onchange="getdate(this.value)">       <option value="0" selected>city</option>       <option value="1">brisbane</option>       <option value="2">sydney</option>       <option value="3">melbourne</option>       <option value="4">adelaide</option>       <option value="5">perth</option>     </select>   </p>      <div id="dateinput"></div>   <p align="center">      <input type="submit"> </form></p> </body> </html> 

php file

<?php require'connect.php'; date_default_timezone_set('australia/sydney');  $q=$_get["q"]; $sql="select date date schedule lounge = '".$q."' , date >= now() , date <= now() + interval 14 day order date asc";   $result=mysql_query($sql); $num=mysql_numrows($result); $i=0; echo"<center><select name='dateinput' id='dateinput'></center>";  while ($i < $num) {     $datum=mysql_result($result,$i,"date");     $day = date('l js m', strtotime($datum));     echo "<option value=$datum>$day</option>";     $i++; }  if (!mysql_query($query)){     die('error: ' . mysql_error()); } mysql_close(); ?>  

second javascript function belongs html file. , attach event (on want call second function) php file.

<select name="dateinput" id="dateinput" onchange="......."></select> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -