Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preference Voting - Radio Buttons

Status
Not open for further replies.

Billybonga

IS-IT--Management
Jun 22, 2002
72
GB
Is it possible to or has some ever done so:

I designing an Intranet site to allow e-polling on employees.

There may be 3 users with preferences 1, 2, 3 i.e.

NAME | 1 | 2 | 3
-------------------------
TOM | O | O | O
-------------------------
MARY | O | O | O
-------------------------
JOHN | O | O | O


Voters should vote in preference as to who they like ... now for that catch ... Obviously if someone selects Tom as 1 then 1 cannot be chosen for Mary or John same as if the then choose Mary as 2, then John cannot be 1, 2

Preferences can be in any order but cannot be selected by others

Is this be best way to go or would drop downs be better?

Regards,

Billybong
 
Here's a quick example:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var ppl = ["radioTom", "radioMary", "radioJohn"];

function resetList(obj) {
   thisName = obj.name;
   thisNum = parseInt(obj.value, 10);
   var arrIndex = 0;
   for (var i = 0; i < 3; i++) {
      if (thisName == ppl[i]) {
         arrIndex = i;
      }
   }
   document.forms["frm"].elements[ppl[thisNum - 1]][arrIndex].checked = true;
   var temp = ppl[arrIndex];
   ppl[arrIndex] = ppl[thisNum - 1];
   ppl[thisNum - 1] = temp;
}

</script>

<style type="text/css"></style>
</head>
<body>
<form id="frm" action="" method="post" onsubmit="">
   <div id="divTom">
      <span>Tom</span>
      <input type="radio" name="radioTom" value="1" checked="checked" onclick="resetList(this)" />1
      <input type="radio" name="radioTom" value="2" onclick="resetList(this)" />2
      <input type="radio" name="radioTom" value="3" onclick="resetList(this)" />3
   </div>
   <div id="divMary">
      <span>Mary</span>
      <input type="radio" name="radioMary" value="1" onclick="resetList(this)" />1
      <input type="radio" name="radioMary" value="2" checked="checked" onclick="resetList(this)" />2
      <input type="radio" name="radioMary" value="3" onclick="resetList(this)" />3
   </div>
   <div id="divJohn">
      <span>John</span>
      <input type="radio" name="radioJohn" value="1" onclick="resetList(this)" />1
      <input type="radio" name="radioJohn" value="2" onclick="resetList(this)" />2
      <input type="radio" name="radioJohn" value="3" checked="checked" onclick="resetList(this)" />3
   </div>
</form>
</body>
</html>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Thanks kaht for your time and effort on this.
Hopefully it'll lead me in the right direction.

Only things is see critical with this is the default values could display preference to an individual.

I'll see if i can play with what you have given me and try to come up with some sort of form validator side that check that no two values are alike.

I'm not an expert on java so i'l see what I can play with unless you can suggest any tricks.

Many thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top