Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery live('change', function() wont trigger drop down
    text
    copied!<p>Anyone can see anything wrong with this code? It is connected to a php function that echos Json data. I am running Jquery 1.9.1. I belive the problem is at the end of the Jquery script, but I can´t find any solution...</p> <pre><code>var formObject = { run : function(obj) { if (obj.val() === '') { obj.nextAll('.update').html('&lt;option value=""&gt;----&lt;/option&gt;').attr('disabled', true); } else { var id = obj.attr('id'); var v = obj.val(); jQuery.getJSON('func/blankett_func.php', { id : id, value : v }, function(data) { if (!data.error) { obj.next('.update').html(data.list).removeAttr('disabled'); } else { obj.nextAll('.update').html('&lt;option value=""&gt;----&lt;/option&gt;').attr('disabled', true); } }); } } }; $(function() { $('.update').live('change', function() { formObject.run($(this)); }); }); </code></pre> <p>The Php function: <pre><code>$id = $_GET['id']; $value = $_GET['value']; try { $objDb = new PDO('mysql:host=localhost;dbname=blankett', 'root', 'root'); $objDb-&gt;exec('SET CHARACTER SET utf8'); $sql = "SELECT * FROM `region` WHERE `master_id` = ?"; $statement = $objDb-&gt;prepare($sql); $statement-&gt;execute(array($value)); $list = $statement-&gt;fetchAll(PDO::FETCH_ASSOC); if (!empty($list)) { $out = array('&lt;option value=""&gt;Select one&lt;/option&gt;'); foreach($list as $row) { $out[] = '&lt;option value="'.$row['id'].'"&gt;'.$row['region'].'&lt;/option&gt;'; } echo json_encode(array('error' =&gt; false, 'list' =&gt; implode('', $out))); } else { echo json_encode(array('error' =&gt; true)); } } catch(PDOException $e) { echo json_encode(array('error' =&gt; true)); } } else { echo json_encode(array('error' =&gt; true)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload