How to populate listbox with textbox?

How do you add item in listbox through the textbox?

  • Answer:

    This can be done with a little javascript. Here's an example <html> <head> <script type="text/javascript" language="javascript"> function addNewItem() { // Retrieve the elements from the document body var textbox = document.getElementById('MyTextbox'); var listbox = document.getElementById('MyListbox'); // Now we need to create a new 'option' tag to add to MyListbox var newOption = document.createElement('option'); newOption.value = textbox.value; // The value that this option will have newOption.innerHTML = textbox.value; // The displayed text inside of the <option> tags // Finally, add the new option to the listbox listbox.appendChild(newOption); } </script> </head> <body> <input id="MyTextbox" type="textbox" /> <input type="button" value="Add Item" onclick="javascript:addNewItem()" /> <br /><br /> <select id="MyListbox" size="10"> <option value="apples">Apples</option> <option value="oranges">Oranges</option> <option value="bananas">Bananas</option> </select> </body> </html>

wiki.answers.com Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.