sciencebear Posted May 21, 2010 Share Posted May 21, 2010 I have an onClick function that I only want to run on the first click. (For example, if the user clicks away and then clicks back I don't want it to run again.) How can I do this? Link to comment https://forums.phpfreaks.com/topic/202497-onclick-first-click-only/ Share on other sites More sharing options...
ricmetal Posted May 21, 2010 Share Posted May 21, 2010 look at $_SESSION variables Link to comment https://forums.phpfreaks.com/topic/202497-onclick-first-click-only/#findComment-1061606 Share on other sites More sharing options...
RichardRotterdam Posted May 21, 2010 Share Posted May 21, 2010 use a variable that stores if something has been clicked. example: <script type="text/javascript"> window.onload = function() { // use var to check if a link has been clicked var clickedOnce = false; document.getElementById('my_link').onclick = function() { // will only alert when clickedOnce is false if(!clickedOnce) { clickedOnce = true; alert('you clicked me'); } } } </script> <a href=# id="my_link">clickme</a> Link to comment https://forums.phpfreaks.com/topic/202497-onclick-first-click-only/#findComment-1061623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.