/    Sign up×
Community /Pin to ProfileBookmark

On my website: [url]http://www.chamillionairechat.com[/url] I have added a Poll on the left hand side on the page in the menu bar.

Could someone please help me make it, so when you click on an option, it automatically counts your vote and refrehes the poll, so it shows the results of the poll.

So in other words, you don’t need to press vote, it will automatically count the vote for you when you click a option.

Thanksm I will really appreciate your help ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 14.2008 — remove "checked" from the first option, then add:

[code=html]<script type='text/javascript'>
/* <![CDATA[ */
window.onload = function(){
var w = document.getElementsByTagName('input');
for(var i = 0; i < w.length; i++){
if(w[i].type == 'radio'){
if(window.addEventListener)
w[i].addEventListener('click', function(){document.forms[0].submit();}, false);
else if(window.attachEvent)
w[i].attachEvent('onclick', function(){document.forms[0].submit();});
else
w[i].onclick = function(){document.forms[0].submit();};
};
};
};
/* ]]> */
</script>[/code]
untested.
Copy linkTweet thisAlerts:
@DanaldinhoauthorFeb 14.2008 — remove "checked" from the first option, then add:

[code=html]<script type='text/javascript'>
/* <![CDATA[ */
window.onload = function(){
var w = document.getElementsByTagName('input');
for(var i = 0; i < w.length; i++){
if(w[i].type == 'radio'){
if(window.addEventListener)
w[i].addEventListener('click', function(){document.forms[0].submit();}, false);
else if(window.attachEvent)
w[i].attachEvent('onclick', function(){document.forms[0].submit();});
else
w[i].onclick = function(){document.forms[0].submit();};
};
};
};
/* ]]> */
</script>[/code]
untested.[/QUOTE]

I don't understand you ?

Please explain a bit more

And here is my vote.php

&lt;?php

$self = $_SERVER['PHP_SELF'];

// get the poll data
$dat_file = 'poll.dat';
$poll_data = unserialize(file_get_contents($dat_file));

// define question, options, and votes
$question = $poll_data['question'];
$options = $poll_data['options'];
$votes = $poll_data['votes'];

// count the number of options and votes
$total_options = count($options);
$total_votes = array_sum($votes);

// if the vote form has not been submitted
if(!isset($_POST['vote'])) {
?&gt;
&lt;form action="&lt;?php echo $self; ?&gt;" method="post"&gt;
&lt;?php

echo('&lt;b&gt;');
echo $question."&lt;br /&gt;&lt;br /&gt;n";
echo('&lt;/b&gt;');

for($x=0; $x&lt;$total_options; $x++) {
echo '&lt;input type="radio" name="option" value="'.$x.'"';
if($x == 0) echo ' checked';
echo ' /&gt; '.$options[$x]."&lt;br /&gt;n";
}

?&gt;
&lt;br /&gt;
&lt;input type="submit" name="vote" value="Vote" /&gt;
&lt;input type="submit" name="vote" value="View" /&gt;
&lt;/form&gt;
&lt;?php
} else {
// if the vote form has been submitted

<i> </i>if($_POST['vote'] == 'Vote') {
<i> </i> // if the user clicked 'Vote'
<i> </i> $poll_data['votes'][$_POST['option']]++;
<i> </i> $handle = fopen($dat_file,'w');
<i> </i> fwrite($handle,serialize($poll_data));
<i> </i> fclose($handle);
<i> </i> require('results.php');
<i> </i>} else {
<i> </i> // else, the user clicked 'View'
<i> </i> require('results.php');
<i> </i>}
}
?&gt;
Copy linkTweet thisAlerts:
@scragarFeb 14.2008 — I can't explain it any better, just remove the "checked" atribute from the first option and add that javascript.
Copy linkTweet thisAlerts:
@DanaldinhoauthorMar 15.2008 — Ok thanks ?
×

Success!

Help @Danaldinho spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...