how to bind html select in order by text in jquery -


i have json string as

 json={"0":"-select-","10":"a","5":"b","14":"c"}; 

which returned php code in ordered text a,b,c

i binding json string select box in jquery as

$.each(json,function(k,v){     $('#usercityres').append('<option value="'+k+'">'+v+'</option>'); }); 

but gives select list in order value as

<select name="citylist" id="usercityres">  <option value="0">select</option>  <option value="5">b</option>  <option value="10">a</option>  <option value="14">c</option> </select> 

i needed in order text "-select-,a,b,c" order, not value. $.each function of jquery appending in order of value.

please me in how sort , display in order text( working fine in mozilla browser , not in ie , chrome)

thanks in advance

if want preserve order of items, suggest using array/collection

[{ "key": "0", "value": "-select-"}, { "key": "10", "value": "a"}, { "key": "5", "value": "b"}, { "key": "14", "value": "c"}] 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -