posted 15 years ago
Hi, I have three drop downs for country ,state, and city on my screen. i am populating them through AJAX. My problem is when i have already selected state and submit my form for validation my selected state is getting lost. I have used following code:-
function fetchStates(selectedState)
{
var countryid=document.getElementById("advertisercountry").value;
//alert(countryid);
$.ajax({
type:"get",
url:"mDealsUserRegistrationController?strAction=fetchstates",
data:"countryid="+countryid,
dataType:"xml",
success:function(xml)
{
$("#advertiserstate").empty();
$(xml).find('state').each(function()
{
var stateid=$(this).find('stateid').text();
var statename=$(this).find('statename').text();
if(selectedState==stateid)
{alert(selectedState); $("#advertiserstate").append("<option value="+stateid+" selected='selected'>"+statename+"</option>")}
else{$("#advertiserstate").append("<option value="+stateid+">"+statename+"</option>")}
})
//alert(selectedState);
if(selectedState == 0)
{
$("#advertiserstate").append("<option value='' selected='selected'>--Select State--</option>")
}
}
});
}
Please help.
Thanks in advance.