Note that there are some explanatory texts on larger screens.

plurals
  1. POfail to create\edit select element with JS
    text
    copied!<p>i am trying to create a select element with JS or even edit an existing one yet i seem to be missing something. this is done in Joomla if this matters.</p> <p>this is my code:</p> <pre><code> var option = document.createElement("option"); var select = document.createElement("select"); select.setAttribute("id", "chooseCat"); for(int i=0;i&lt;LevelNames.Length;i++) { option.innerHTML = LevelNames[i]; option.setAttribute("value",LevelIds[i]); document.getElementById("cat_chooser").appendChild(option); document.getElementById("cat_chooser").options.add(option); } select.onchange=function() { CreateDDL(this.options[this.selectedIndex].value); } var test = document.getElementById("cat_chooser"); test.appendChild(select); document.add(select); document.appendChild(select); </code></pre> <p>this is all the ways i tried doing that. cat_chooser is a SELECT added manualy to the page.</p> <p>any help?</p> <p><strong>EDIT:</strong> this is the whole code :</p> <pre><code> &lt;script language=\"javascript\" type=\"text/javascript\"&gt; //definitions var LevelNames = new Array(); var LevelIds = new Array(); boolean isFirstRun = true; //this functions create a Drop Down List function CreateDDL(pid=null){ //pass arrays for client side, henceforth : var id,var parent_it, var title &lt;?php echo "\n".$id."\n".$parent_id."\n".$title."\n\n";?&gt; if(pid){ } if(isFirstRun) { for(int i=0; i &lt; id.length;i++) { //if category has no parent if(parent_id[i] == "1") { LevelIds.push(id[i]); LevelNames.push(title[i]); } } } else{ for(int i=0; i &lt; id.length;i++) { //if is a son of our target? if(parent_id[i] == pid) { LevelIds.push(id[i]); LevelNames.push(title[i]); } } } //finished first run isFirstRun=false; //create the actuall drop down //var option = document.createElement("option"); var select = document.createElement("select"); select.setAttribute("id", "chooseCat"); for(var i=0;i&lt;LevelNames.length;i++) { var option = new Option(/* Label */ LevelNames[i], /* Value */ LevelIds[i] ); select.options.add(option); } select.onchange=function() { CreateDDL(this.options[this.selectedIndex].value); } var test = document.getElementById("cat_chooser"); test.appendChild(select); //document.add(select); //document.appendChild(select); document.body.appendChild(select); } CreateDDL(); &lt;/script&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