Form added to page

Asked

Viewed 35 times

0

I have a javascript function that loads Formulars from XML files. The files contain only forms codes, inputs, selects, etc... This data is dynamically loaded to a page via the jquery load() function. Soon after another function populates these fields retrieving data from a previously loaded json array. However, this data does not appear in the fields, as if the form was not loaded/synchronized on the page. Has anyone experienced it? Has a light?

  • You can put here the code and xml or json you are using?

  • Sorry, the forms are in HTML and not in XML as mentioned. I use the following statement to add the form: '$('#div'). load(form.html);' . For popular, I use an array of objects comparing the key name with the control name. If they are equal, add the array value to the control.

1 answer

0

The Method load() of Jquery is asynchronous.

What happens is that when you make the call it probably hasn’t generated the elements yet.

You can avoid this by using the callback of the method.

Ex:

$('#div').load('formulario.html',function(){
     //adicionar aqui o preenchimento dos campos
});
  • Perfect!!! It worked! Thank you!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.