So I'm sorta new to javascript, but am not new to C++ which seems similar to javascript. Anyways, what I'm trying to do is have a function load when someone clicks on the page so I'm using. <body onClick="function();"> Code (markup): To load the function when clicking on the page. The problem I have is I only want this action to happen once when the page is clicked on, and my first solution I came up with was an IF statement that uses a variable to decide if this function has been done before. Example: If (x==0) { function code; x=x+1; } Code (markup): Basic programing pretty much. But I can't figure out how to use it outside or inside a function both ways aren't working. I understand a function is just a group of scripts that are called, but I want to be able to control the controller of the function pretty much(if that makes sense to you). Much help would be appreciated. If this isn't a clear explanation tell me and I'll clear up whatever doesn't make sense. (it's late)
Could you not put it the other way around? So something like this: functionName() { if (clickedOnce == 0) { //your code here //finish with clickedOnce = 1; } }