javascript - erasing textfield after submit content -


i want erase content of textfield after adding option select list, here html code example:

<select size="15" style="width:230px" style="text-align:right" id="theaterselectcontrol">                             <option>111</option>                             <option>222</option>                             <option>333</option>                         </select>                         <p>                         </p>                         <form>                             <input type="text" name="theater_name" value="" id="theater_name" style="width:225px">                         </form>                 </td>             </tr>             <tr>                 <td align="right">                     <input type="button" onclick="createoption()" value="add">      <!-- add list button -->                 </td> </tr> 

here js code:

function createoption() {     var theaterselectcontrol = document.getelementbyid('theaterselectcontrol');      var currenttext = document.getelementbyid('theater_name').value;     var objoption = document.createelement("option");     objoption.text = currenttext ;     objoption.value = currenttext ;     theaterselectcontrol.options.add(objoption);      document.getelementbyid('add_option').onclick = createoption;            resetfield(); }  function resetfield()  {     document.getelementbyid('theater_name').value = ""; } 

what doing wrong?

thanks

your event listener inside function calls, it's causing problems.

document.getelementbyid('add_option').onclick = createoption;  

put outside createoption();


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -