javascript - Concat parameter syntax -


not sure how ask question, if suggestions title please let me know...

i have following function retrieves via ajax information of json file. function can see below:

setoptionssettings("[data-machine-brand-options]", apiurlmachinebrands, 'name');  function setoptionssettings(htmlelement, url, apiparameter) {      $.ajax({         datatype: "json",         url: url,         // create generic solution spinner         beforesend: function(xhr) {             $('main').html('<div class="spinner"><div class="hori-verti-centering"><div class="bounce bounce1"></div><div class="bounce bounce2"></div><div class="bounce bounce3"></div></div></div>');             setheader(xhr);         },         success: function (data) {             $.each(data, function(i) {                 $(htmlelement).append("<option id=" + data[i].id + " value=" + data[i].apiparameter + ">" + data[i].apiparameter + "</option>");             });         }     });     return {}; } 

i'm trying set apiparamter when call function setoptionsettings can place name of parameter need call. in case parameter name. how can insert function works?

i tried following , other solutions nothing work, suggestions?

$(htmlelement).append("<option id=" + data[i].id + " value=" + data[i]. + apiparameter + ">" + data[i]. + apiparameter + "</option>"); 

to access object property using string key use bracket notation i.e data[i][apiparameter]

as using jquery create element using it.

$(htmlelement).append($('<option></option>', {     "id": data[i].id,     "value": data[i][apiparameter] })); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -