php - Populated options from database doesn't run script on change -


i load options select database (which loads options) , trying run script when selected option changes (which doesn't run) script below

<script> $(function() {      function subrace()     {         var race = $("#race").val();          console.log(race + "!");     }      $("#race")       .selectmenu()       .selectmenu(       {           change:  subrace()       })       .selectmenu("menuwidget")       .addclass("overflow");  });  </script>   <select name="race" id="race"> <?php  $dbhost = "localhost"; $dbuser = "dand_user"; $dbpass = "****************"; $dbname = "dand_user";  $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);  $query = "select * races order name asc";  $result = mysqli_query($mysqli, $query); $x = 0; while($row = $result->fetch_array(mysqli_both)) {     echo"    <option value=\"" . $row['name'] . "\">" . $row['name'] . "</option>\n";     $x++; }  if($x === 0) {     echo"<option disabled selected>no races available</option>"; } ?> </select> 

the script is in head element , once script run i'll adjusting console peice see if runs

through working on code further discovered answer can't lay out function want run in situation need enclose in function

<script> $(function() {      function subrace()     {         var race = $("#race").val();          console.log(race + "!");     }      $("#race")       .selectmenu()       .selectmenu(       {           change:  function( event, ui )           {               subrace();           }       })       .selectmenu("menuwidget")       .addclass("overflow");  });  </script>   <select name="race" id="race"> <?php  $dbhost = "localhost"; $dbuser = "dand_user"; $dbpass = "****************"; $dbname = "dand_user";  $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);  $query = "select * races order name asc";  $result = mysqli_query($mysqli, $query); $x = 0; while($row = $result->fetch_array(mysqli_both)) {     echo"    <option value=\"" . $row['name'] . "\">" . $row['name'] . "</option>\n";     $x++; }  if($x === 0) {     echo"<option disabled selected>no races available</option>"; } ?> </select> 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -