Jump to content

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


nita

Recommended Posts

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:

<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>

 

and a Java Script used to get latitude and longitude:

 

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");
}

 

I'm totaly stuck here. What do i do wrong?

Will appreciate any help and thank you in advance.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Tried with that:

 

<form name="latlon" action="test2a.php" method='post' onchange="usePointFromPostcode(document.getElementById('postcode').value); usePointFromPostcode1(document.getElementById('postcode1').value); ">

 

dosn't work as it should.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.