Jump to content

blueyoshi55

Members
  • Posts

    4
  • Joined

  • Last visited

blueyoshi55's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I added a "view results" button/link! In place of the "submit" button, put in this code: <table style="margin-top:10px;"><tr><td><div style="font-size: 9pt; cursor:pointer; color:#d90909" onclick="getVote('100')"><u>View results</u></div></td><td style="width:5px;"></td><td><input type="button" value="Submit" onclick="sendVote()" /></td></tr></table> And also, in the poll_vote.php file, put this after "$vote = $_REQUEST['vote'];" if(vote!=100){ and make sure to close the "if" statement (with a "}") right before the end of the php code ("?>") All it does is send the integer "100" directly to the "getVote()" function (bypassing the "sendVote()" function), and the php file is set so that if the integer is 100, it skips over the whole part where it edits poll_result.txt, and it just displays the results! This completes the simplest insertable AJAX poll I have come across... really nice.
  2. Thank you, James!!!!! Yes, that worked......... For anyone else, make sure to change the last line of function sendVote(), instead of "alert(radio.value);", to "getVote(radio.value);". Coincidentally, the PHP part of my poll (poll_vote.php) was also bad, because I had altered it to accommodate for more than two options. Then I thought, "Wow, does that mean this would've worked without the extra functions (as above)?". But no, I tried different variations of using "getVote()" directly, and it didn't work, so apparently the above functions were necessary. For anyone wondering, here's the code for poll_vote.php to accommodate multiple options: <?php$vote = $_REQUEST['vote'];//get content of textfile$filename = "poll_result.txt";$content = file($filename);//put content in array$array = explode("||", $content[0]);//count vote$array[$vote]++;//insert votes to txt file$insertvote = $array[0]."||".$array[1]."||".$array[2]."||".$array[3];$fp = fopen($filename,"w");fputs($fp,$insertvote);fclose($fp);static $total=0;foreach($array as $value){$total = $value + $total;}?><table style="width: 100%; height: 250px;"><tr><td>Option 1</td><td><?php echo(100*round($array[0]/$total,2)); ?>%</td></tr><tr><td>Option 2</td><td><?php echo(100*round($array[1]/$total,2)); ?>%</td></tr><tr><td>Option 3</td><td><?php echo(100*round($array[2]/$total,2)); ?>%</td></tr><tr><td>Option 4</td><td><?php echo(100*round($array[3]/$total,2)); ?>%</td></tr></table><p style="color:#d90909; font-size: 9pt; font-family:'lucida grande',tahoma,sans-serif;"><i>*after vote message*</i></p>
  3. I thought this would be easy but I can't figure it out... The AJAX poll example is here: http://www.w3schools...p_ajax_poll.asp As it is, the value is submitted through the function upon clicking the radio button: <input type="radio" name="vote" value="0" onclick="getVote(this.value)" /> So to change this, I thought I'd just have to remove the "onclick" from the radio buttons, and put it in a submit button. (I found out that "submit" buttons reload the page, so I changed the type to "button"): <input type="button" value="Submit" onclick="getVote(this.value)" /> This successfully calls the function, as <div id="poll"> is replaced with the poll results. But they're all 0%. The value of the ticked radio button is not getting through. (And it's not a display issue-- the poll_result.txt is all 0's.) So does "this.value" only work if it's inside the radio button input code? What should I put in its place so that it gets the value from whatever radio button is selected?
×
×
  • Create New...