TS wrote:
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[i];
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>
--
Rob