473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Radio button validation on survey -Any ideas?

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

Jul 23 '05 #1
4 2827
ASM
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.


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
Jul 23 '05 #2
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"

Jul 23 '05 #3
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
Jul 23 '05 #4
ASM
TS wrote:
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[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
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
8
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the...
6
by: Blinky | last post by:
Hi all, I have a dynamically generated page that can have 1 or more radio buttons. I am using javascript with onsubmit in the form statement to make sure a radio button is selected before...
9
by: wreed | last post by:
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements.type; if (temp == "radio") { for (x =...
8
by: Binx | last post by:
Please help! Does anyone know how to set up radio buttons to send their info from flash to a PHP script that will email me the results? I have been trying to get this thing to work for weeks, and...
1
by: Jerim79 | last post by:
I have a simple 3 page registration form. One form, one "data validation" script and one "insert into database" script. The customer bounces back and forth from the form to the verification script...
5
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button...
0
by: djjohnst | last post by:
I am creating a form(survey) where the first question is a yes/no question using two radio buttons. If they click "yes" I want to then make the next 4 questions required. I am not sure how to do...
4
by: pureadrenaline | last post by:
Hey Guys, Please could anyone help me out with the following form I need to create a validation on the email field only if the user checked the radio button named Email. Thanks in advance. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.