Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to "disable" javascript function after being ran once
    primarykey
    data
    text
    <p>So I have two html buttons that each run a different function (both functions are below). Basically, you click one of the two buttons to add a Google Maps actionlistener to the map. I've successfully got that to work. The only problem is that I only want the actionlistener to be available one click. After that one click I want the user to have to click another button before the actionlistener "listens" again. I hope that makes sense.</p> <pre><code> function addLaunch() { google.maps.event.addListener(map, "click", function(event) { marker = new google.maps.Marker({ position: event.latLng, map: map }); infowindow.open(map, marker); }); }; function addFishing() { google.maps.event.addListener(map, "click", function(event) { marker = new google.maps.Marker({ position: event.latLng, map: map }); fishinfowindow.open(map, marker); }); }; </code></pre> <p>So I just tried this:</p> <pre><code>function addLaunch(setBoolean) { var clicked = new Boolean(false); clicked.boolValue = setBoolean; if (clicked = true) { google.maps.event.addListener(map, "click", function(event) { marker = new google.maps.Marker({ position: event.latLng, map: map }); infowindow.open(map, marker); clicked.boolValue = false; }); } else { google.maps.event.clearListeners(map, "click"); } }; </code></pre> <p>and it didn't work..... Please point me in the right direction... (BTW, the button passed "true" to the 'setBoolean'.</p> <p>This works to disable all actionlisteners after the first click. But it doesn't reset after the button is clicked again.</p> <pre><code> var temp = true; function addLaunch() { if (temp == true) { google.maps.event.addListener(map, "click", function(event) { marker = new google.maps.Marker({ position: event.latLng, map: map }); infowindow.open(map, marker); temp = false; if (temp == false) { google.maps.event.clearListeners(map, "click"); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload