anb90
anb90

Reputation: 73

Fill array of <select> using ajax

How could i fill array of select with options using ajax:

<select name = "names[1]"></select>
<select name = "names[2]"></select>
<select name = "names[3]"></select>
<select name = "names[4]"></select>
<select name = "names[5]"></select>

note: thats just for example, but iwant it dynamic so i dont know how many of select i do have, but all of them will contain same options.

Upvotes: 0

Views: 87

Answers (1)

chandu
chandu

Reputation: 2276

use little bit of jquery here.

$(function(){
var jsonArray = []; //your json array. 
var html = "";
for(i=0;i<jsonArray.length;i++){
 html += "<select name="'+jsonArray.name[i]+'"></select>"
}

$("#locationId").append(html); //append your html where ever you want

})

Upvotes: 1

Related Questions