Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add item to a listbox using jquery

Tags:

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> 

like image 348
andrew Sullivan Avatar asked Oct 04 '10 09:10

andrew Sullivan


People also ask

How to add item in ListBox using jQuery?

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.

How to add value in ListBox using JavaScript?

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>


1 Answers

$('#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. 
like image 197
Reigel Avatar answered Sep 23 '22 23:09

Reigel