Radio button validation on survey -Any ideas?

T

TS

My objective:
To create a survey that asks people to rate a list of things in order
of importance. I wish to prevent them from just rating every item in
the list the same value.

For example the Page would look roughly like this:
Please rate the following in order of importance:
Item Rating
Apples 1 2 3
Orange 1 2 3
Peaches 1 2 3

The radio buttons in code would be like this:
input type="radio" name="FruitRating" value="1"
input type="radio" name="FruitRating" value="2"
input type="radio" name="FruitRating" value="3"

Where 1, 2, 3 are radio buttons. If some one was to rate all three as
1's for example I would like to uncheck one or simply ask them to
rescore the items with the same value.

How would this thing be done? I have the form with all of the radio
buttons and every thing works fine.

Thanks in advance, especially for examples
 
A

ASM

TS said:
My objective:
To create a survey that asks people to rate a list of things in order
of importance. I wish to prevent them from just rating every item in
the list the same value.

with a serie of radio-buttons *having same name*
you can only check *one* of them
(checking several is impossible)

the form will send the value of checked button
(ignoring all others of same name)

there is nothing more to know
 
T

TS

Sorry I did not make this clear. Each Item has a series of radio
buttons with different names.
I should have said this:
The radio buttons in code would be like this:

input type="radio" name="Apples" value="1"
input type="radio" name="Apples" value="2"
input type="radio" name="Apples" value="3"

input type="radio" name="Oranges" value="1"
input type="radio" name="Oranges" value="2"
input type="radio" name="Oranges" value="3"

input type="radio" name="Peaches" value="1"
input type="radio" name="Peaches" value="2"
input type="radio" name="Peaches" value="3"


How do I detect when someone has scored Apples and Oranges as "1"
 
R

RobG

TS said:
My objective:
To create a survey that asks people to rate a list of things in order
of importance. I wish to prevent them from just rating every item in
the list the same value.

For example the Page would look roughly like this:
Please rate the following in order of importance:
Item Rating
Apples 1 2 3
Orange 1 2 3
Peaches 1 2 3

The radio buttons in code would be like this:
input type="radio" name="FruitRating" value="1"
input type="radio" name="FruitRating" value="2"
input type="radio" name="FruitRating" value="3"

Where 1, 2, 3 are radio buttons. If some one was to rate all three as
1's for example I would like to uncheck one or simply ask them to
rescore the items with the same value.

How would this thing be done? I have the form with all of the radio
buttons and every thing works fine.

Thanks in advance, especially for examples

The easy part is getting the values, the hard part is the algorithm
for what is an unacceptable result. The script below gets the value
of all the checked checkboxes in a form and puts them into an array -
what you do with them after that is up to you.

If you provide some algorithm for analysis of the answers to determine
acceptability, then you may get some help on implementing it. :)

One checkbox must always be checked, so you should decide which one
that will be and put it in the source - maybe have a zero choice for
the default with 'no opinion' or such.



<script type="text/javascript">

function checkChecks( f ){
var answers = [];
var el, els = f.elements;
var i, j = els.length;
for ( i=0; i<j; i++ ) {
el = els;
if ( 'input' == el.nodeName.toLowerCase() &&
'radio' == el.type && el.checked ) {
answers.push( el.name + ':' + el.value );
}
}
alert( 'Here are the answers:\n' + answers.join('\n') );
}

</script>


<form action="" id="fruitRating" onsubmit="checkChecks(this);">
<table>
<tr>
<th>Fruit name</th>
<th>Good</th>
<th>Bad</th>
<th>Ugly</th>
</tr>
<tr>
<td>Apple</td>
<td><input type="radio" name="apple" value="1" checked></td>
<td><input type="radio" name="apple" value="2"></td>
<td><input type="radio" name="apple" value="3"></td>
</tr>
<tr>
<td>Orange</td>
<td><input type="radio" name="orange" value="1" checked></td>
<td><input type="radio" name="orange" value="2"></td>
<td><input type="radio" name="orange" value="3"></td>
</tr>
<tr>
<td>Pear</td>
<td><input type="radio" name="pear" value="1" checked></td>
<td><input type="radio" name="pear" value="2"></td>
<td><input type="radio" name="pear" value="3"></td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="reset">
<input type="button" value="Check answers"
onclick="checkChecks(this.form)">
</td>
</tr>
</table>
</form>
 
A

ASM

TS said:
Sorry I did not make this clear. Each Item has a series of radio
buttons with different names.

absolutly not they don't
I see 3 groups of radios buttons
inside each group,
radio-buttons have same name (Apples, Oranges, Peaches)
inside each group you can check only one and one alone button
I should have said this:
The radio buttons in code would be like this:

input type="radio" name="Apples" value="1"
input type="radio" name="Apples" value="2"
input type="radio" name="Apples" value="3"

input type="radio" name="Oranges" value="1"
input type="radio" name="Oranges" value="2"
input type="radio" name="Oranges" value="3"

input type="radio" name="Peaches" value="1"
input type="radio" name="Peaches" value="2"
input type="radio" name="Peaches" value="3"


How do I detect when someone has scored Apples and Oranges as "1"

In JS ?

supposing your form is nammed : "nameOfMyForm"

var A = document.nameOfMyForm.Apples;
for(var i=0;i<A.length;i++)
if(A.checked) alert('Apples = '+A.value);

or with a function :

function fruitChecked(fruit) {
var A = document.forms['nameOfMyForm'].elements[fruit];
for(var i=0;i<A.length;i++)
if(A.checked) alert('checked '+fruit+' = '+A.value);
}

<a href="javascript:fruitChecked('Apples')">Apples which one ?</A>
<a href="javascript:fruitChecked('Oranges')">Oranges which one ?</A>
<a href="javascript:fruitChecked('Peaches')">Peaches which one ?</A>


To detect by server side : it is automatic

<form action="page.php" blah >

will send an url this kind :
http;//server.name/site.name/page.php?Apples=1&Oranges=2&Peaches=1

if
value of checked Apples = 1
value of checked Oranges = 2
value of checked Peaches = 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top