Reputation: 1491
I making a tic tac toe game I have this button, but I could like to count the number of times a user clicks it that way I can use it as my tie game condition when clicks = 8 and no winner has been determined. How do I pass and increment the number of times I click this button?
do I use the javascript onclick event?
print('<input type="submit" name="submit_button" value = "Go">');
if(isset($_POST[submit_button]))
{
do stuff
}
Upvotes: 0
Views: 2215
Reputation: 39522
PHP won't solve your problem here, as it is only server side. Declare a variable numClicks
in your JavaScript, and change the input
to this:
<input type="submit" name="submit_button" onclick="increaseClicks()" value = "Go">
Then you can define increaseClicks
to be
function increaseClicks(){
numClicks++;
if(numClicks >= 8){
//dostuff
}
}
Upvotes: 3