So I have a form with some fields and then radio buttons that will change the last part of the form using Ajax. I am able to do this part, but now I have to load some data in the form. The data give me the form's last part and the values to put in the fields of that part.
Here's the problem: While Ajax loads the last fields (depending on the checked radio button), my script continues and inserts the data in the form, so when the last fields remain empty (they were not done loading..)
Here's a part of my code:
$('input[name=radioName]').each(function(){
if($(this).val() == radioValueToCheck){
$(this).prop('checked', true);
changeType(this); //my function that loads the ajax and put it in the form
}
});
alert(document.getElementById('TypeDiv').innerHTML); //div still not updated
$.each(formData, function(index, fieldName){
setNewValue(fieldName, infoExpense[fieldName]); //custom function to insert new values
});
alert(document.getElementById('TypeDiv').innerHTML); //NOW the div is updated!.... =/
The form still end up updated, so I believe the problem is not with the ajax function..