AJAX voting

This example includes four elements:

① HTML form
② JavaScript
③ PHP page
④ Text file to store the results

1. HTML form

This is an HTML page. It contains a simple HTML form, and a connection to a JavaScript file:

<html>
<head>
<script src="poll.js"></script>
</head>
<body>
<div id="poll">
<h2>Do you like PHP and AJAX so far?</h2>
<form>
Yes:
<input type="radio" name="vote"
value="0" onclick="getVote(this.value)">
<br />
No:
<input type="radio" name="vote"
value="1" onclick="getVote(this.value)">
</form>
</div>
</body>
</html>

Example Explanation - HTML Form

As you can see , the HTML page above contains a simple HTML form with a <div> element with two radio buttons.

The form works like this:

· When the user selects "yes" or "no", an event will be triggered

· When the event is triggered, the getVote() function will be executed.

· Surrounding the form is a <div> named "poll". When data is returned from the getVote() function, the returned data replaces the form.


Continuing Learning
||
<html> <head> <script src="poll.js"></script> </head> <body> <div id="poll"> <h2>Do you like PHP and AJAX so far?</h2> <form> Yes: <input type="radio" name="vote" value="0" onclick="getVote(this.value)"> <br /> No: <input type="radio" name="vote" value="1" onclick="getVote(this.value)"> </form> </div> </body> </html>
submitReset Code