Note that there are some explanatory texts on larger screens.

plurals
  1. POselectbox doesn't change by ajax
    primarykey
    data
    text
    <p>I have ajax code that display the name of the cities(in selectbox) according the area that has been chosen:</p> <pre><code>&lt;?PHP if ($_POST) { ?&gt; $(document).ready(function(){ $('#areaID').filter(function(){ var areaID=$('#areaID').val(); var cityID=&lt;?PHP echo $cityID ?&gt;; $('#cityID').load('js/ajax/getCities.php?areaID=' + areaID+'&amp;cityID=' + cityID); return false; }); }); &lt;?PHP }else { ?&gt; $(function () { function updateCitySelectBox() { var areaID = $('#areaID').val(); $('#cityID').load('js/ajax/getCities.php?areaID=' + areaID); return false; } updateCitySelectBox(); $('#areaID').change(updateCitySelectBox); }); &lt;?PHP } ?&gt; </code></pre> <p>The problem is - after user submit the form and get error (i.e - forget to fill some field), user can change the area but the cities select box doesn't change according the new area.</p> <p>What is wrong with the code?</p> <pre><code>&lt;p&gt;&lt;label&gt;area&lt;/label&gt; &lt;select name='areaID' id='areaID'&gt; &lt;?PHP $query = mysql_query("SELECT * FROM `areas` ORDER BY id ASC "); while($index = mysql_fetch_array($query)) { $db_area_id = $index['id']; $db_area_name = $index['name']; if ($db_area_id == $areaID) echo "&lt;option value='$db_area_id' selected&gt;$db_area_name&lt;/option&gt;"; else echo "&lt;option value='$db_area_id'&gt;$db_area_name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;span&gt;*&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;label&gt;City&lt;/label&gt; &lt;select id='cityID' name='cityID'&gt; &lt;/select&gt; &lt;/p&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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