drisate Posted February 18, 2014 Share Posted February 18, 2014 Hey guys!I am using a script i found here (http://vikku.info/programming/geodata/geonames-get-country-state-city-hierarchy.htm) It works really nice for what I need to do but I have only one problem. When the client enters data but forget something, the form returns an error and the POST values are inserted in eachinputs so they don't need to start the whole form. My problem is I can't seem to find a way to auto select the pre-entered data ...I made a pastie of my code herehttp://pastie.org/8743532So fare, I tried adding the selected option id inside the select tag like this:<option value="<?=$_POST[continent]?>"></option>But that did not work ...I also tried playing with the window.onload part by adding more getplaces() like this: window.onload = function() { <?php if ($_POST[continent]){ echo 'getplaces('.$_POST[continent].',\'country\');'."\n"; }else{ echo 'getplaces(6295630,\'continent\');'."\n"; } if ($_POST[country]){echo 'getplaces('.$_POST[country].',\'country\');'."\n";} if ($_POST[province]){echo 'getplaces('.$_POST[province].',\'province\');'."\n";} if ($_POST[region]){echo 'getplaces('.$_POST[region].',\'region\');'."\n";} if ($_POST[city]){echo 'getplaces('.$_POST[city].',\'city\');'."\n";} ?> } But that did not work ...I also tried playing with the listPlaces() function like this: for(var i=0;i<counts;i++){ who.options[who.options.length] = new Option(jData.geonames[i].name,jData.geonames[i].geonameId); if (jData.geonames[i].geonameId==whos){ who.options[who.options.length].selected = true; } } But you guessed it right ... it did not work ... I am out of options. I would hate having to change the script ... Any help would be apreciated! Quote Link to comment https://forums.phpfreaks.com/topic/286289-list-of-countrystatecity-in-a-hierarchy-using-geonames-webservice/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.