0

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

}
1
  • submit_button should be "submit_button" Commented Aug 19, 2012 at 1:47

1 Answer 1

3

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
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Do I think pass the variables back into my php script? Because all my game logic is being done server side.
If you wish to pass data back to the server, then I'd suggest AJAX. Though doing some of the game logic client-side would be much faster.
agree with someKittens unless you want to store the number click for each user in the database, client script should handle the clicks and at the end send results to server to save game score or something

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.