Click here to Skip to main content
15,881,172 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: Radio Buttons (long answer) Pin
enhzflep29-Dec-09 14:14
enhzflep29-Dec-09 14:14 
GeneralRe: Radio Buttons (long answer) Pin
thebiostyle30-Dec-09 7:31
thebiostyle30-Dec-09 7:31 
GeneralRe: Radio Buttons (long answer) Pin
enhzflep30-Dec-09 11:56
enhzflep30-Dec-09 11:56 
GeneralRe: Radio Buttons (long answer) Pin
thebiostyle30-Dec-09 12:17
thebiostyle30-Dec-09 12:17 
GeneralRe: Radio Buttons Pin
enhzflep30-Dec-09 13:20
enhzflep30-Dec-09 13:20 
GeneralRe: Radio Buttons Pin
thebiostyle30-Dec-09 13:34
thebiostyle30-Dec-09 13:34 
GeneralRe: Radio Buttons [modified x2] Pin
enhzflep30-Dec-09 13:41
enhzflep30-Dec-09 13:41 
GeneralRe: Radio Buttons Pin
thebiostyle30-Dec-09 13:59
thebiostyle30-Dec-09 13:59 
Okay, so I mainly use Firefox, and I posted on the homepage of the site, the our site is best viewed with Firefox, so thats okay, as long as in those other browsers that it was able to view radio buttons then it will do just fine.   But when I edited it to fit the actual results page, it submitted no info.   So, here is both files, with what I have edited to fit....


poll.php
--------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Poll</title>
<script type="text/javascript">
function byId(e){return document.getElementById(e);}
function byName(e){return document.getElementsByName(e);}
function changeState(el, stateMod){el.state ^= stateMod;}

function updateImg(el)
{
     imgs = Array("rb1.png", "rb2.png", "rb3.png", "rb4.png");
     el.src = imgs[el.state];
}

function drawRadioGroup(groupName)
{
     var elements, i, count;
     elements = byName(groupName);
     count = elements.length;
     for (i=0; i<count; i++)
          updateImg(elements[i]);
}

function doClick(el)
{
     var elements, i, count;
     elements = byName(el.name);
     for (i=0; i<elements.length; i++)
     {
          elements[i].state &= 1;
          updateImg(elements[i]);
     }
     el.state |= 2;
     updateImg(el);
}

function getRadioGroupValue(groupName)
{    
     result = "none selected";
     elements = byName(groupName);
     count = elements.length;
     for (i=0; i<count; i++)
     {
          if (elements[i].state >= 2)
               result = elements[i].value;
     }
     return result;
}

function addRadioButton(groupName, optionValue, labelValue, tgtContainer)
{
     lblObj = document.createElement("label");
     lblText = document.createTextNode(labelValue);
    
     // create the miage object
     imgObj = document.createElement("img");
     imgObj.name = groupName;
     imgObj.src = "rb1.png";
     imgObj.width = "12";
     imgObj.height = "12";
     imgObj.value = optionValue;
     imgObj.onmouseout =   function(){ changeState(this, 1); updateImg(this); }   //onmouseout="changeState(this, 1); updateImg(this)"
     imgObj.onmouseover = function(){ changeState(this, 1); updateImg(this); }
     imgObj.onclick = function(){doClick(this);}
    
     lblObj.appendChild(imgObj);          // add the image to the label object
     lblObj.appendChild(lblText);     // add the label text after the img - text appears to the right of the image

     tgtContainer.appendChild(lblObj);     // add the label object to the target container

     // add the img object to the target container
     newLineObj = document.createElement("br");     // and add a new-line, ready for the next item to be added
     tgtContainer.appendChild(newLineObj);
}

function createGroup(groupName)
{
     choices = Array("Firefox", "Chrome", "Navigator", "Safari", "Opera", "Internet Explorer");
     for (i=0; i<choices.length; i++)
          addRadioButton(groupName, choices[i], choices[i], byId("radioHolder"));
}

function getHiddenValue()
{
     chosenValue = getRadioGroupValue("radioGroup1");
     byId("pollChoice").value = chosenValue;
     return 1;
}

function test2(){alert(getRadioGroupValue("radioGroup1"));}
</script>
</head>
<body onload="createGroup('radioGroup1', 10);">
<span style="color: rgb(255, 0, 0);">
<h3>What is your Preferred browser?</h3>
     <div id = "radioHolder"></div>
      <form action="Poll Results.php" method="post" onsubmit="getHiddenValue();">
            <input type="hidden" name="vote" id="pollChoice" value="<?php echo $i; ?>"/>
           <br /><input type="submit" value="Vote" style="border-color: rgb(255, 0, 0); color: rgb(255, 0, 0); font-family: Arial; font-weight: bold; font-size: 12px; background-color: rgb(0, 0, 0);"><br/></span>
</body>
</html>
--------------------------------------------------------------------------------------------------------

Poll Results.php
--------------------------------------------------------------------------------------------------------
<?php
$file = "votes.txt";
$title = "What is your Preferred Browser?";
$choices = array("Firefox",  
"Chrome",
"Navigator",
"Safari",
"Opera",
"Inernet Explorer");
?>
<body>
<h3 style="color: rgb(255, 0, 0);">Poll Results</h3>
<p><span style="color: rgb(255, 0, 0);">
<?php

   $votes = file($file);
   $total = 0;
   $vote = $_POST["vote"];


   if(isset($vote)){
      $votes[$vote] = $votes[$vote]+1;
   }


   $handle = fopen($file,"w");

   foreach($votes as $v){
      $total += $v;
      fputs($handle,chop($v)."\n");
   }

   fclose($handle);

   for($i=0;$i<count($choices);$i++){
      echo "{$choices[$i]} has {$votes[$i]} votes.<br />";
   }
?>
</p>
<p>Total: <?php echo $total; ?> votes.</span></p>
</body>
--------------------------------------------------------------------------------------------------------

Thanks, hopefully you can fix it so that it will work.
GeneralRe: Radio Buttons Pin
enhzflep31-Dec-09 7:04
enhzflep31-Dec-09 7:04 
GeneralRe: Radio Buttons Pin
thebiostyle31-Dec-09 7:13
thebiostyle31-Dec-09 7:13 
GeneralRe: Radio Buttons Pin
enhzflep31-Dec-09 13:05
enhzflep31-Dec-09 13:05 
GeneralRe: Radio Buttons Pin
thebiostyle31-Dec-09 18:13
thebiostyle31-Dec-09 18:13 
GeneralRe: Radio Buttons [modified] Pin
enhzflep31-Dec-09 19:41
enhzflep31-Dec-09 19:41 
GeneralRe: Radio Buttons Pin
thebiostyle31-Dec-09 21:44
thebiostyle31-Dec-09 21:44 
QuestionFind the differences betwween two arrays Pin
Marc Firth24-Dec-09 0:51
Marc Firth24-Dec-09 0:51 
AnswerRe: Find the differences betwween two arrays Pin
Luc Pattyn28-Dec-09 10:43
sitebuilderLuc Pattyn28-Dec-09 10:43 
QuestionHow to use postback in php Pin
sarang_k23-Dec-09 22:28
sarang_k23-Dec-09 22:28 
AnswerRe: How to use postback in php Pin
Marc Firth24-Dec-09 1:25
Marc Firth24-Dec-09 1:25 
Questionwarning message Pin
kamalesh574323-Dec-09 15:27
kamalesh574323-Dec-09 15:27 
AnswerRe: warning message Pin
Marc Firth24-Dec-09 1:27
Marc Firth24-Dec-09 1:27 
QuestionSTL vector trouble Pin
Daniel 'Tak' M.22-Dec-09 5:27
Daniel 'Tak' M.22-Dec-09 5:27 
Questionhelp with imap_search function Pin
cjoki21-Dec-09 7:08
cjoki21-Dec-09 7:08 
AnswerRe: help with imap_search function Pin
cjoki21-Dec-09 10:14
cjoki21-Dec-09 10:14 
QuestionPERL script help Pin
David Hoffman19-Dec-09 15:05
David Hoffman19-Dec-09 15:05 
AnswerRe: PERL script help Pin
David Hoffman19-Dec-09 21:45
David Hoffman19-Dec-09 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.