So, I am writing a code that when user clicks on a map. It retrieves the coordinate values, and tries to bind it (show its value) in a texbox. I have tested it, the coordinate and click event works but I guess there is a problem with binding it to textbox. any suggestions on how to fix this?
the code:
<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function (options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function (e) {
var lonlat = map.getLonLatFromPixel(e.xy);
alert("You clicked near " + lonlat.lat + " N, " +
+lonlat.lon + " E");
$('#latlon').value = lonlat;
}
});
</script>
and how I define the textbox:
<input type="text" name="coordinates" id="latlon" value="" Font-Names="Tahoma" Font-Size="10pt" Width="95%" />
The error message:
Uncaught TypeError: Cannot set property 'value' of null
OpenLayers.Control.Click.OpenLayers.Class.trigger