Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i populate a dropdown list by selecting the value from another dropdown list?
    primarykey
    data
    text
    <p>I have build two drop downs (like state and city) by fetching the records of both drop downs from mysql database and am trying to build the tool in which, while selecting any value (i.e. any state) from first drop down, at that time in second drop down (in city) only those values (cities) under that value (state) selected in first drop down should be visible. </p> <p>Here's my code:</p> <pre><code>&lt;tr&gt; &lt;td id='hed'&gt;&lt;span style="font-family:verdana,geneva,sans- serif"&gt;State&lt;/state&gt;&lt;/td&gt; &lt;td&gt; &lt;?php $dbcon = mysql_connect("@ip","@username","@password"); if($dbcon) { mysql_select_db("@database", $dbcon); } else { die('error connecting to the database'); } $qry = "select @value(state) from @tablename "; $result = mysql_query($qry) or die(mysql_error()); $dropdown = "&lt;select name='@valuename' id='officeItemList' style='cursor:pointer;cursor:hand;'&gt;"; while($row = mysql_fetch_array($result)) { $dropdown .= "\r\n&lt;option value='{$row['@value']}' &gt; {$row['@value']} &lt;/option&gt;"; } $dropdown .= "\r\n&lt;/select&gt;"; echo $dropdown; mysql_close($dbcon); ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id='hed'&gt;&lt;span style="font-family:verdana,geneva,sans-serif"&gt;City&lt;/span&gt;&lt;/td&gt; &lt;td colspan="1"&gt; &lt;?php $dbcon = mysql_connect("@ip","@username","@password"); if($dbcon) { mysql_select_db("@database", $dbcon); } else { die('error connecting to the database'); } $qry = "select value2(city) from @tablename where "; $result = mysql_query($qry) or die(mysql_error()); $dropdown = "&lt;select name='@value2' id='officeItemList' style='cursor:pointer;cursor:hand;'&gt;"; while($row = mysql_fetch_array($result)) { $dropdown .= "\r\n&lt;option value='{$row['@value2']}' &gt; {$row['@value2']} &lt;/option&gt;"; } $dropdown .= "\r\n&lt;/select&gt;"; echo $dropdown; mysql_close($dbcon); ?&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre>
    singulars
    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.
 

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