How to add item to a listBox using jquery.
for example in the following listbox
<option value="1"></option> <option value="2">item 2</option> <option value="3">item 3</option> <option value="4">item 4</option> <option value="0">All</option>
Add (Insert) Items to ASP.Net ListBox using jQueryInside this event handler, first the value from the TextBox is fetched and then a HTML OPTION element is created. The TextBox value is set to the InnerHtml and Value property of the OPTION element. Finally the OPTION element is appended to the ASP.Net ListBox control.
Step 1: For this, we will first use some controls like TextBox (txtValue) to add the value in the ListBox, ListBox (lstValue) and an Add and Delete Button as in the following: <input name="txtValue" type="text" /> <input type="button" name="add" value="Add" onclick="addValue();" /> <select name="lstValue" multiple>
$('#Select1').append('<option value="5">item 5</option>'); // adds item 5 at the end $('#Select1 option').eq(0).after('<option value="new">new</option>'); // add new at the second position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With