javascript - PHP Poll and Values -
i'm new php, , i'm trying create poll. each answer has value (from 0 3) , when press "submit" want different message appear different result. if sum of values 0-4, example, want appear message. if it's 5-9, different message.
<label><span class="badge">1</span>do website?</label> <p> <label>no</label> <input type="radio" name="poll" value="0"><br/> <label>maybe</label> <input type="radio" name="poll" value="1"><br/> <label>i don't know</label> <input type="radio" name="poll" value="2"><br/> <label>yes</label> <input type="radio" name="poll" value="3"><br/> </p> <input type="button" class="btn-danger" id="btn" value="submit">
this html. can find examples database.thanks!
if understand question correctly, trying add poll system, without integration of database store each vote.
this problem if want people different computers able vote on same page. without database, can store each vote locally javascript. users have use poll on same browser, , without refreshing page.
if that's want, this:
var sum = 0; var count = 0; var avg = 0; $("#btn").on("click", function() { count++; sum = +sum + +$('input[name=poll]:checked').val(); avg = sum / count; $("#print").html("the average is: " + avg + ", , sum is: " + sum); if(sum < 5) { alert("the sum below 5!"); } else { alert("the sum above 5!"); } });
note used jquery here, can done without.
edit: alerts should "sum" , not "average".
edit 2: php approach - single vote - without database:
html
<form action="process_vote.php" method="post"> <label><span class="badge">1</span>do website?</label> <p> <label>no</label> <input type="radio" name="poll" value="no"><br/> <label>maybe</label> <input type="radio" name="poll" value="maybe"><br/> <label>i don't know</label> <input type="radio" name="poll" value="i don't know"><br/> <label>yes</label> <input type="radio" name="poll" value="yes"><br/> </p> <input type="submit" class="btn-danger" id="btn" value="submit"> </form>
php
<?php $var = $_post['poll']; echo "the user voted: $var"; ?>
Comments
Post a Comment