> <script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
marker = new google.maps.Marker({
position : latlng,
title : "hello world",
draggable : true
});
marker.setMap(map)
}
function write(){
//var positon = marker.getPosition()
alert('position')
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
<input type='button' value ='position' onClick="write()">
</body>
</html>
whenever i click on the button called position the map disappears why is that so ?
write() is a reserved Javascript function — when you call it, you are executing document.write() which (since you are calling it after the document has already finished writing) will rewrite the whole page.
Try renaming it myWrite() instead.