Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically fill <select> without all <option> showing simultaneously
    text
    copied!<p>I have a select anchor with id=antibiotic that is dynamically filled. Based on the selection I want to then dynamically fill the next listview with id=dose. The code below is working, but all of the option anchors dynamically selected for id=dose show at the same time. I've tried selecting one choice programatically and then refreshing to no avail. Any other ideas? I'm using jquery mobile.</p> <pre><code>&lt;body&gt; &lt;select Onchange='changer($(this).val())' class="antibiotic" id="antibiotic" data-native-menu="false"&gt; &lt;option value=""&gt;Select Antibiotic&lt;/option&gt; &lt;?php $hostname = "xxxx"; $username = "xxxx"; $dbname = "xxxx"; $password = "xxxx"; $usertable = "renalAdjust"; $yourfield = "antimicrobial"; //Connecting to your database $link = mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); //Fetching from your database table. $query = "SELECT * FROM $usertable"; $result = mysql_query($query); if ($result) { $antimicrobial = array(); while($row = mysql_fetch_array($result)) { $name = $row["$yourfield"]; array_push($antimicrobial, $name); } mysql_close($link); $antimicrobial2 = array_unique($antimicrobial); foreach($antimicrobial2 as $item) { $item2 = str_replace(" ","_", $item); ?&gt;&lt;option class='opt' value=&lt;?php echo $item2 ?&gt;&gt;&lt;?php echo $item ?&gt;&lt;/option&gt;&lt;?php } }?&gt; &lt;/select&gt; &lt;select class="dose" id="dose" data-native-menu="false"&gt; &lt;option value=""&gt;Select Dose&lt;/option&gt; &lt;/select&gt; &lt;select id="Creatinine Clearance" data-native-menu="false"&gt; &lt;option value=""&gt;Select Creatinine Clearance&lt;/option&gt; &lt;/select&gt; &lt;script&gt; function changer(val){ var dataString = 'id='+ val.replace("_"," ","g"); $.post("renalAdjust2.php", {id: dataString}, function(data){ var doses = data.split("----"); for (var i in doses){ $('&lt;option&gt;').val(doses[i]).text(doses[i]).appendTo('.dose'); } }); } &lt;/script&gt; &lt;/body&gt; </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