Ajax not returning value back to the calling script

Ajax not returning value back to the calling script

Hello,
After 5 days of picking at the code I excepted defeat and come seeking help..lol
Working on a user registration form and in it i have 2 dropdown list, one for country and one for state/province.

On page load the country dropdown list is loaded and it works. 
When a user selects a country the state/province dropdown list successfully loaded and this also works.

Not working:
in the event the user submits the form I like to have the states/province reloaded with the initial selection at the top of the menu list. As of now i cant even reload the state/prv dropdown list if the user hits the submit button.

any help you can provide would be greatly appreciated.
tk




  1. <label>Select province (required field)</label><br/>
  2. <select name="sel_Iprovince" id="IprovinceID">
  3. <option value="">Select Province</option>
  4. <?php 
  5. if (!empty($_POST['sel_Iprovince'])){
  6. echo "<script> getProvince('" . $_POST['sel_Icountry'] . "', '" . $_POST['sel_Iprovince']. "'); </script>";
  7. }
  8. ?>
  9. </select>

  1. function getProvince(countryVal, provinceId) {
  2. var GeoCountry = countryVal;
  3. var GeoProvince = provinceId;
  4. alert('test1=:'+GeoCountry+' '+ GeoProvince);
  5.     $.ajax({
  6.         type: "POST",
  7.         url: "get_tprovince.php",        
  8. data: {'GeocountryID': GeoCountry, 'GeoprovinceID': GeoProvince},
  9.         success: function(data){
  10. if(typeof(GeoCountry) !== 'undefined'){
  11. alert('test2=:'+ data);
  12. $("#IprovinceID").html(data); 
  13. }  
  14. if(typeof(GeoProvince) !== 'undefined'){
  15. alert('test3=:'+ data);
  16. $("#IprovinceID").html(data); 
  17. }  
  18.         }
  19.     });
  20. }