Connecting Tech Pros Worldwide Help | Site Map

Radio button validation on survey -Any ideas?

  #1  
Old July 23rd, 2005, 10:34 PM
TS
Guest
 
Posts: n/a
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

  #2  
Old July 23rd, 2005, 10:34 PM
ASM
Guest
 
Posts: n/a

re: Radio button validation on survey -Any ideas?


TS wrote:[color=blue]
> 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.[/color]

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


--
Stephane Moriaux et son [moins] vieux Mac
  #3  
Old July 23rd, 2005, 10:34 PM
TS
Guest
 
Posts: n/a

re: Radio button validation on survey -Any ideas?


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"

  #4  
Old July 23rd, 2005, 10:34 PM
RobG
Guest
 
Posts: n/a

re: Radio button validation on survey -Any ideas?


TS wrote:[color=blue]
> 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
>[/color]

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
  #5  
Old July 23rd, 2005, 10:35 PM
ASM
Guest
 
Posts: n/a

re: Radio button validation on survey -Any ideas?


TS wrote:[color=blue]
> Sorry I did not make this clear. Each Item has a series of radio
> buttons with different names.[/color]

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
[color=blue]
> 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"[/color]

In JS ?

supposing your form is nammed : "nameOfMyForm"

var A = document.nameOfMyForm.Apples;
for(var i=0;i<A.length;i++)
if(A[i].checked) alert('Apples = '+A[i].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[i].checked) alert('checked '+fruit+' = '+A[i].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

--
Stephane Moriaux et son [moins] vieux Mac
Closed Thread