• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Selected value getting lost on form Submit

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you post back the page it is like erasing a whiteboard. You will need to go ahead and repopulate all of the fields.

Eric
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic