/    Sign up×
Community /Pin to ProfileBookmark

Problem With Onchange Event In The Form (Geting Latitude And Longitude)

Hi there !

What i’m traying to do is to get latitude and longitude form imputed postcodes.
Which works fine as long as i stick to only one input (first or second seperate).
I can’t get it to work once i try with both of them.
i’m using onchange event ..

Please ake a look at the form:

[CODE]
<form name=”latlon” action=”test2a.php” method=’post’ onchange=”return usePointFromPostcode(document.getElementById(‘postcode’).value) && usePointFromPostcode1(document.getElementById(‘postcode1’).value) “>
<input id=”postcode” type=”text” size=”10″ /><br>
<input id=”postcode1″ type=”text” size=”10″/><br>
Latitude:<input name=”lat” type=”text” id=”lat” size=”10″/><br />
Longitude:<input name=”lon” type=”text” id=”lon” size=”10″/><br><br>
Latitude:<input name=”lat1″ type=”text” id=”lat1″ size=”10″/><br />
Longitude:<input name=”lon1″ type=”text” id=”lon1″ size=”10″/>
<input type=”submit” value=”Get Lat / Lon”/>
</form>
[/CODE]

and a Java Script used to get latitude and longitude:

[CODE]
function usePointFromPostcode(postcode, callbackFunction) {

localSearch.setSearchCompleteCallback(null,
function() {

if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
document.forms[‘latlon’].lat.value=resultLat;
document.forms[‘latlon’].lon.value=resultLng;
callbackFunction(point);
}else{
alert(“Postcode not found!”);
}
});

localSearch.execute(postcode + “, UK”);
}
function usePointFromPostcode1(postcode1, callbackFunction) {

localSearch.setSearchCompleteCallback(null,
function() {

if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
document.forms[‘latlon’].lat1.value=resultLat;
document.forms[‘latlon’].lon1.value=resultLng;
callbackFunction(point);
}else{
alert(“Postcode not found!”);
}
});

localSearch.execute(postcode1 + “, UK”);
}
[/CODE]

I’m totaly stuck here. What do i do wrong?
Will appreciate any help and thank you in advance.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@nitapitaauthorNov 15.2012 — Maybe i'm not clear enough here ...

all i want is to type in 2 postodes in the form so i can get their lat / lon and pass these values to another page, (hidden inputs to be used)

im not so much into javascript but maybe there is some other way ...

problem is in the form (getting lat / lon works fine)

any suggestions ...

Thank You
Copy linkTweet thisAlerts:
@007JulienNov 15.2012 — Display the onchange event on each input with the same function !
Copy linkTweet thisAlerts:
@nitapitaauthorNov 15.2012 — having some time helps !!!

Solved

Postcode:<input id="postcode" name="postcode" type="text" size="10" onchange="usePointFromPostcode(document.getElementById('postcode').value)" /><br>

Postcode 1:<input id="postcode1" name="postcode1"type="text" size="10" onchange="usePointFromPostcode1(document.getElementById('postcode1').value)"/><br>
×

Success!

Help @nitapita spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...