Jquery: Timing issue in jquery
<p>I am using PHP with zend framework as the technology. I am sending my encoded json string via controller and sending it to my view.
Now the actual scenario is that, When I submit my form and if the errors occur than what ever items I have selected, needs to be appear on my form.
This works fine when I debug the jquery, but if I do it directly its not working.</p>

<p>Below is the code I am using:-</p>

<pre><code>function repopulateItems() {
   if (typeof existingItems != 'undefined') {
       $.each(existingItems, function() {
           repopulateItemById(this.id);
           $("#description\\[" + counter + "\\]").val(this.description);
           $("#quantity\\[" + counter + "\\]").val(this.quantity);

       });
   }

}


function repopulateItemById(id){
       var rowId = createItem('prepareItemForCreate');
       var proElement = $("#id\\[" + rowId + "\\]");
       id = $.trim( id );
       $("#id\\[" + rowId + "\\] option").filter(function() {
           return $(this).val() == id;
       }).attr('selected', true);
       proElement.change();
       $(this).val('');
       $(this).focus();
}
</code></pre>

<p>In the above code after the execution of the repopulateItemById(), the item is being displayed with its value as per the database. But now if you notice in the repopulateItems(), after the execution of repopulateItemById(), I am resetting some of the properties because I want to have them as entered by the user. So the actual problem occurs here. If I start debugging, the values entered by the user is properly displayed but if I do it without debugging, it displays the items only with its actual database value.</p>
