Note that there are some explanatory texts on larger screens.

plurals
  1. POset selected value for AUTO POPULATED select box in jquery
    text
    copied!<p>i have 2 select box on my page named [Municipality] and [brgy] but the [brgy] select is auto populated by what ever the user selects on [Municipality] select box using change() event in jquery..the following are my code for this..</p> <p>This is for the Municipality select box that populates the brgy select box </p> <pre><code>$("select[name='Municipality']").change(function(){ // get the selected option value of country var optionValue1=$(this).val(); $("#Dbrgy") .html('ajaxLoader.gif') .load('all.php', {Muni:true, MunVal: optionValue1, status: 1}, function(response) { if(response) { $("#Dbrgy").css('display', ''); } else { $("#Dbrgy").css('display', 'none'); } }); }); </code></pre> <p>and this is the all.php that process the request</p> <pre><code>&lt;?if(isset($_POST['Muni'])) { $value = $_POST['MunVal']; $q=mysql_query("SELECT * FROM `tbl_brgy` WHERE `brgy_id`='$value'"); ?&gt; &lt;select name="brgy" id="brgy"class="input" style='width:150px;'&gt; &lt;option value='0'&gt;&amp;raquo;SELECT&lt;/option&gt; &lt;?while($result=mysql_fetch_array($q)){?&gt; &lt;option value="&lt;?php echo $result['brgy#'] ?&gt;"&gt;&lt;?php echo $result['name'] ?&gt; &lt;/option&gt;&lt;?}?&gt; &lt;/select&gt; &lt;?}?&gt; </code></pre> <p>now after populating the brgy select box i need to set selected value on it that was retrived from mysql database. </p> <p>and this is how i set the selected value from database</p> <pre><code>if(isset($_POST['RetrieveUpdate'])) { $qure=mysql_query("SELECT * FROM `tbl_touristspot` where `spot_id`=$_POST[Id]") or die (mysql_error()); while($result=mysql_fetch_array($qure)) { echo"&lt;script&gt; $('#brgy').val($result[brgy]);&lt;/script&gt;"; } </code></pre> <p>but that seems not working.</p>
 

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