473,851 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="FruitRati ng" value="1"
input type="radio" name="FruitRati ng" value="2"
input type="radio" name="FruitRati ng" 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 2847
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="FruitRati ng" value="1"
input type="radio" name="FruitRati ng" value="2"
input type="radio" name="FruitRati ng" 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.toL owerCase() &&
'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="check Checks(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="checkC hecks(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 : "nameOfMyFo rm"

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

or with a function :

function fruitChecked(fr uit) {
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="javascrip t:fruitChecked( 'Apples')">Appl es which one ?</A>
<a href="javascrip t:fruitChecked( 'Oranges')">Ora nges which one ?</A>
<a href="javascrip t:fruitChecked( 'Peaches')">Pea ches which one ?</A>
To detect by server side : it is automatic

<form action="page.ph p" blah >

will send an url this kind :
http;//server.name/site.name/page.php?Apples =1&Oranges=2&Pe aches=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
13469
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 related to checkboxes. Thanks!!!
4
11045
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 to: if one is clicked, its corresponding information will become available on another document, if it's not clicked no information will be provided. If multiple buttons are clicked their information will available on the same document. I'm not...
8
5910
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 control. See the code below * Page.aspx: <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="Webspace.Test" %>
6
3131
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 allowing the page to be submitted. At the moment it only works when there is 2 or more radio buttons on the page. How can I get the radio button validation working when there is only 1 radio on the page ?
9
9308
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 = 0; x < the_form.elements.length - 1; x++) {
8
11037
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 I still can not get it to work right. Right now, I have a survey that looks like this, and it sends the input text just fine, but when I get the email, all the radio button info is not there. I can provide files or code if it helps. I really...
1
4149
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 until the data is all correct. (When I say bounces, I mean logically. All the customer ever sees is the registration form, plus or minus error messages.) The problem I am having, is that if verification fails, the customer is redirected to the...
5
2733
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 are selected it should giv message dat select a radio button. else it should go to other page. My code works fine when there are more than 1 radio button but when only 1 radio button is der dat time it does not work
0
1163
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 this. I thought I could use a custom validator, and using code behind use an IF statement. However, I am not sure how to pass the value from the radio button group. I am having trouble. If this is easy forgive me, I am new at this .net game.
4
3034
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. <form action="" method="get"> <div align="center"> <table border="0" cellspacing="0" cellpadding="0">
0
9744
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10670
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10725
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10352
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5931
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.