Jump to content

List of country/state/city in a hierarchy using geonames webservice


Recommended Posts

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 each
inputs 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 here
http://pastie.org/8743532

So 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!
 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.