Chciałby w formularzu rejestracyjnym przesylac od razu dane lokalizacyjne miasta (w danm województwie) w poscie w tym celu odpalam fukcję js
geoCodeCity przed submitem().
Mój kod:
<script type="text/javascript"> function geoCodeCity() { var wojs = new Array('Dolnośląskie', 'Kujawsko-Pomorskie', 'Lubelskie', 'Lubuskie', 'Łódzkie', 'Małopolskie', 'Mazowieckie', 'Opolskie', 'Podkarpackie', 'Podlaskie', 'Pomorskie', 'Śląskie', 'Świętokrzyskie', 'Warmińsko-Mazurskie', 'Wielkopolskie', 'Zachodniopomorskie'); var city = document.getElementById('city').value; var id_woj = document.getElementById('region').value; var woj = wojs[(id_woj-1)]; var adres = city+', '+woj; geo = new GClientGeocoder(); geo.getLocations(adres,function(response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0]} alert(location1.lat); document.getElementById('x').value = location1.lat; document.getElementById('y').value = location1.lon; } }); document.getElementById('f').submit(); } </script> <form method="post" enctype="multipart/form-data" id="f"> <input type="hidden" value="fCRegister" name="form"> <input type="hidden" id="x" name="x"> <input type="hidden" id="y" name="y"> ... <p> <input type="text" id="city" name="city" value="<?= Utils::isValue($d['city']);?>" class="text-input large-input"> </p> <p> <?php print UtilsHTML::selectBox("id_region","id_region","name","", $wojs, Utils::isValue($d['id_region']), 'region'); ?> </p> <!--- id pola input id_region to 'region' --> <input type="button" class="button" value="Zarejestruj się" onclick="geoCodeCity()"> </form>
Jak widac w kodzie używam metody alert w celach testowych , żeby wydrukowała mi odpowiednią współrzędną. Niestety
firebug wyrzuca błąd o takiej treści: ( przez ułamek sekundy wyświetla się ten alert ale potem leci submit i taki o to blad w firebugu:)
prompt aborted by user
[Break On This Error] throw Components.Exception...by user", Cr.NS_ERROR_NOT_AVAILABLE);
Czy ktoś może mi coś doradzić ?