Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic dropdownlist value from database
    primarykey
    data
    text
    <p>How I can connect the value of my main dropdown into sub dropdown. Value of dropdown is from the database main_list and sub_list tables. And also the body onload is not working. </p> <p>Main_list</p> <pre><code>id | value | id_no 1 | colors | 1 2 | fruits | 2 3 | animals| 3 4 | flowers| 4 </code></pre> <p>sub_list</p> <pre><code>id | value | category 1 | red | 1 2 | blue | 1 3 | mango | 2 4 | banana | 2 5 | cat | 3 6 | dog | 3 7 | lotus | 4 8 | lily | 4 </code></pre> <p>And this my Code</p> <p>PHP :</p> <pre><code>&lt;body onload="run()"&gt; &lt;form id="form1" name="form1" method="post" action="&lt;?php $_SERVER['PHP_SELF']?&gt;"&gt; Drop1 &lt;?php $mysqli = new mysqli("localhost", "root", "", "lists"); $result = $mysqli-&gt;query("SELECT * FROM main_list GROUP BY id ORDER BY id"); $option = ''; while($row = $result-&gt;fetch_assoc()) { $option .= '&lt;option value = "'.$row['value'].'"&gt;'.$row['value'].'&lt;/option&gt;'; } ?&gt; &lt;select id="main" name="main" onchange="run()"&gt; &lt;!--Call run() function--&gt; &lt;option selected=selected&gt;Choose&lt;/option&gt; &lt;?php echo $option; ?&gt; &lt;/select&gt;&lt;br&gt;&lt;br&gt; &lt;?php if (isset($_POST['main'])) { $mysqli = new mysqli("localhost", "root", "", "lists"); $result1 = $mysqli-&gt;query("SELECT * FROM sub_list GROUP BY value ORDER BY id"); $option1 = ''; while($row = $result1-&gt;fetch_assoc()) { $option1 .= '&lt;option value = "'.$row['value'].'"&gt;'.$row['value'].'&lt;/option&gt;'; } } echo 'Drop2 '; echo '&lt;select name="sub" id="sub" onchange="run()"&gt; &lt;option value=" " disabled="disabled" selected="selected"&gt;Choose one&lt;/option&gt;'; echo $option1; echo '&lt;/select&gt; '; ?&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>Javascript :</p> <pre><code>&lt;script type="text/javascript"&gt; function run(){ document.getElementById('form1').change() } &lt;/script&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.
    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