Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this code out.</p> <p>PHP:</p> <pre><code>&lt;?php $miscArray = array("misc1", "misc2", "misc3"); $misc = implode(", ", $miscArray); $peopleArray = array("people1", "people2", "people3"); $people = implode(", ", $peopleArray); ?&gt; </code></pre> <p>HTML: </p> <pre><code>&lt;form action="#"&gt; &lt;select id="fileCat"&gt; &lt;option id="misc"&gt;Misc&lt;/option&gt; &lt;option id="miscData" style="display:none"&gt;&lt;?php echo $misc ?&gt;&lt;/option&gt; &lt;option id="people"&gt;People&lt;/option&gt; &lt;option id="peopleData" style="display:none"&gt;&lt;?php echo $people ?&gt;&lt;/option&gt; &lt;/select&gt; &lt;select id="files"&gt;&lt;/select&gt; &lt;/form&gt; </code></pre> <p>JS:</p> <pre><code>init(); function init() { addListeners(); } function addListeners() { document.getElementById("fileCat").onchange = fillSelect; } function fillSelect() { var fileCat = document.getElementById("fileCat"); var imageFiles; switch(fileCat.options[fileCat.selectedIndex].id) { case "misc": imageFiles = document.getElementById("miscData").innerHTML.split(", "); break; case "people": imageFiles = document.getElementById("peopleData").innerHTML.split(", "); break; } var parent = document.getElementById("files"); parent.innerHTML = ""; if(imageFiles.length) { for(var i=0;i&lt;imageFiles.length;i++) { var option = document.createElement("option"); //populate option with corresponding image text option.innerHTML = imageFiles[i]; parent.appendChild(option); } } } </code></pre> <p>I mocked up some data in PHP and then echoed it into a hidden <code>&lt;option&gt;</code> tag for each category. Then, the data is grabbed using a case/switch depending on the id of the selected option.</p>
    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.
 

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