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? Quote 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 Quote 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> Quote Link to comment https://forums.phpfreaks.com/topic/202497-onclick-first-click-only/#findComment-1061623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.