html - Javascript Complete Amateur? -


i have javascript function wrote append select box radiobutton set based on radio button clicked. when 1 clicks 1 or other. problem is, i'm such amateur can't stop adding new select elements span set place them in. keep trying different ways check if element or innerhtml have been set , use check decide whether create select. none of has worked me. can point me in direction of tutorial (i've been searching, tried everything, no fez makes me think simpler problem structure of whole function).

here code, light shed on super helpful. taught myself code know horrible. help!!

function moreinput(vinput)  { var mored = document.getelementbyid('mored'); //document.write(mored);     if(vinput == \"approved\")  {         if(mored.length > 0)    {             mored.removechild(approvedopts);         }         var select = document.createelement(\"select\");         select.options[0] = new option('a');         select.options[1] = new option('b');         select.options[2] = new option('c');         select.setattribute(\"name\",\"approvedoptsa\");     }     if(vinput == \"denied\")    {         //alert(mored.innerhtml);         //if(mored.innerhtml === 'undefined')   {             //mored.removechild(approvedoptsd);             var select = document.createelement(\"select\");             select.options[0] = new option('x');             select.options[1] = new option('y');             select.options[2] = new option('z');             select.setattribute(\"id\",\"approvedoptsd\");             select.         //}     } mored.appendchild(select); 

}

remove elements before add new elements.

this code should work:

<script type=\"text/javascript\">  function moreinput(vinput)  {     var mored = document.getelementbyid('mored');         if(vinput == \"approved\")  {             removeallchildrens(mored);             var select = document.createelement(\"select\");             select.options[0] = new option('comped table');             select.options[1] = new option('comped drink');             select.options[2] = new option('comped cover');             select.setattribute(\"name\",\"approvedoptsa\");         }         if(vinput == \"denied\")    {                 removeallchildrens(mored);                 var select = document.createelement(\"select\");                 select.options[0] = new option('need reserve table');                 select.options[1] = new option('at capacity');                 select.options[2] = new option('private event');                 select.setattribute(\"id\",\"approvedoptsd\");         }     mored.appendchild(select); }  function removeallchildrens(cell) {     if ( cell.haschildnodes() ) {         while ( cell.childnodes.length >= 1 ) {             cell.removechild( cell.firstchild );                }      } }   </script> 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -