The Below example will demonstrate a poll where the result is shown without reloading.
When a user choose an option above, a function called "getVote()" is executed. The function is triggered by the "onclick" event:
The getVote() function does the following:
The page on the server called by the JavaScript above is a PHP file called "poll_vote.html":
The value is sent from the JavaScript, and the following happens:
The text file (poll_result.txt) is where we store the data from the poll.
It is stored like this:
The first number represents the "Yes" votes, the second number represents the "No" votes.
Note: Remember to allow your web server to edit the text file. Do NOT give everyone access, just the web server (PHP).
Your Query was successfully sent!