Hi,I have a form with 10 selectbox, I populated the data via jquery.ajax. but it is very slow in requesting to the server.
this is how I do it.
example I am editing the record of a customer
first selectbox (color)
first I will make request to server via jquery.ajax to get the id of the color selected by the customer during on his registration.
$.ajax({
type:'post',
url:'getcustomercolorid.php',
success:function(data){
var colorid = data.id;
//send another request to server to get all colors to populate in selectbox.
getAllcolors(selected_id);
}
});
function getAllcolors(selected_id){
$.ajax({
type:'post',
url:'getAllcolors.php',
success:function(data){
$.each(data,function(key,val){
if (key == selected_id) { // select the option
$('select#colors').append($('<option selected></option>').val(key).text(val));
} else {
$('select#colors').append($('<option></option>').val(key).text(val));
}
});
//calling another function here to load selectbox
//same procedure above.
//second selectbox(food)
}
});
}
Is this the way to populate selectbox with selected value ? but it is very slow…is there other way to do this ?
Thank you in advance.