Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  30] [ 3]  / answers: 1 / hits: 27677  / 7 Years ago, fri, february 24, 2017, 12:00:00

I am novice in HTML, javaScript or jQuery, I am basically an Oracle DBA and Developer. I need to know how to populate select list with jquery.
I have created a string from database query which is as mentioned below. Now I want this to be populated in a select list.
For example I have the string like:



<select id=my-select name=emplist>
<option value=7839>KING</option>
<option value=7782>CLARK</option>
<option value=7934>MILLER</option>
<option value=21>MAMUN</option></select>


and I like to populate the select list item
called '#SELECT_LIST' with the data above. How can I do that?
Now I want the selct item to be populated with the string.



Please respond, your answer will help me out.



Thanks.


More From » jquery

 Answers
132

You can use jquery to do it:



$(document).ready(function(){

//init data
var arrayList = [
{Id: 100, Name: Abc},
{Id: 200, Name: XYZ}
];

for (var i = 0; i <= arrayList.length; i++) {
$('#SELECT_LIST').append('<option value=' + arrayList[i].Id + '>' + arrayList[i].Name + '</option>');
}

});

[#58792] Wednesday, February 22, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;