14
Category: JavaScript
Passing selected values from listbox to textbox

Sending a selected item from a listbox to a textbox is not a very big deal for a script programmer at server end. But doing it at client-end(browser-end) is really make the involvement of JavaScript. There are others browser-end script to get this type of output but JavaScript is the best client-end scripting for working with any browser at user interaction.

Put the JavaScript in <script> </script> tag and input elements under <body> </body> tag as following:

<script>
function display()

{
var dpt=document.getElementById("DropDownList1");

/*alert(dpt.options[dpt.selectedIndex].value);*/
document.getElementById("category").value =dpt.options[dpt.selectedIndex].value;
}
</script>
< <body> input type="text" name="category" size="50" id="category" />
<select name="sel_category" size="10" multiple="multiple" ID="DropDownList1" runat="server" onchange="display();">
<option>HTML5</option>
<option>CSS</option>
<option>JavaScript</option>
<option>JQuery</option>
<option>PHP</option>
</select> </body>