Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

jQuery select list issue

I have a code something like

    if($('#nodeNo').val() == null){
              cityChange(1);                      
              $('#nodeNo option[value=<%=request.getAttribute("nodeval")%>]').attr('selected','selected');
    }

There is an Ajax call in cityChange(1) to populate the nodeNo select list and then the next statement sets the selected value. However due to parallel execution the above code doesn't work. The ajax call and setting the value executes together. The other Ajax call takes a bit time and by that time the next statement finishes execution. Hence the list is populated correctly but the selected value can't be set.

Pls Help!!

Upvotes: 0

Views: 107

Answers (2)

Sridhar Narasimhan
Sridhar Narasimhan

Reputation: 2653

You are having ajax call and your setting the data source for that select element in the success or complete of ajax call and i suggest you to set the selected value in ajax complete of cityChange(1); method.

Regards,

Upvotes: 1

Tariqulazam
Tariqulazam

Reputation: 4585

You have to transfer

$('#nodeNo option[value=<%=request.getAttribute("nodeval")%>]').attr('selected','selected');

into the ajax success callback inside the cityChange method.

Upvotes: 0

Related Questions