I have this part of code.
I want to put marker, when text in textbox will change – it works with function changeValue() – getting new address.
Then, I want to put this marker, when address variable will change. How do to it?
I tried with this code below, but I get this error:
Error: ReferenceError: changeValue is not defined
What is wrong?
(...)
<asp:TextBox Style="width: 300px;" runat="server" ID="tbStreet" onchange="changeValue()"></asp:TextBox>
(...) // more 5 textboxes
<script type='text/javascript'>
(...) // 2 long string arrays.
var address;
function mapaStart() {
var wspolrzedne = new google.maps.LatLng(52.22105994970536, 19.22609921875007);
var opcjeMapy = {
zoom: 5,
center: wspolrzedne,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapka"), opcjeMapy);
function changeValue() {
var ulica;
var miasto;
var woj1;
var panstwo1;
ulica = document.getElementById("<%=tbStreet.ClientID%>").value;
miasto = document.getElementById("<%=tbCity.ClientID%>").value;
woj1 = woj[document.getElementById("<%=ddlProvince.ClientID%>").value];
panstwo1 = panstwa[document.getElementById("<%=ddlCountry.ClientID%>").value];
address = panstwo1 + ", " + woj1 + ", " + miasto + ", " + ulica;
alert(address);
}
var geokoder = new google.maps.Geocoder();
map.setCenter(address.geometry.location);
var marker = new google.maps.Marker(
{
map: map,
position: address.geometry.location,
}
);
}
</script>
Your changeValue function is local to the mapaStart function. It is not accessible in the global context that HTML click/onchange listeners run in. To make it global, move it outside of the mapaStart function.