Set Selected item in dropdown using jquery
0 down vote favoriteI m having two dropdownlist A and B.Dropdown A will loaded at the time of page load .Dropdown B will load based on dropdown A's selected item and value and I m loading Dropdown B using Json .
Now the problem is I m having a table and i m getting edit values from that html table and I need to refill these values to corresponding dropdowns.
First I set the selected item for Dropdown A by
$("#ctl00_MainContent_A option:contains("'Test' ")").prop('selected', 'selected');
Its working fine , and I load dropdown B by using the A's Selected item text by using Json.
After load B,the new options are loaded into Dropdown B and I m trying to set selected text for dropdown B by same above
$("#ctl00_MainContent_B option:contains("'Test B' ")").prop('selected', 'selected');
now the operation not working . I checked ,when i use each function for Dropdown B's option
$("#ctl00_MainContent_B > option").each(function() {
alert(this.text + ' ' + this.value);
});
Its just give the only one item text and value in alert, not giving the all newly loaded options text and values in alert.
Please give me any solution ..
Thanks in advance