473,408 Members | 2,813 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,408 software developers and data experts.

How to choose an event to trigger for many radio buttons?

hi,

i have some 10 radio buttons meant to take the rating from the user.
ex:

1 2 3 4 5 6 7 8 9 10
looks O O O O O O O O O O

1 2 3 4 5 6 7 8 9 10
features O O O O O O O O O O
..........
..........
..........

total score |______________|

submit button |_______|

the user has to select any one for each row (looks, features etc).
I have to calculate the total % of his rating.

leaving "looks" blank, he cannot go to the next( "features", in this
case) and so on. if he has left "looks" unchosen and tries to check
"features", i should prompt him until he checks a radio button in
"looks".

how can i do this?? on what event should i call a function that does
this??

please help

thanks in advance.

Regards,

Amith
Jul 20 '05 #1
6 5165
Given my limited skills, this is what I would do...

Have the HTML for the "features" <radio> buttons be disabled
<input type="radio" name="features" value="1" disabled>
<input type="radio" name="features" value="2" disabled>
<input type="radio" name="features" value="3" disabled>
<input type="radio" name="features" value="4" disabled>

Then, in the onclick event for "looks", make all the "features" enabled
<input type="radio" name="looks" value="1" onclick="clickLooks">
<input type="radio" name="looks" value="2" onclick="clickLooks">
<input type="radio" name="looks" value="3" onclick="clickLooks">
<input type="radio" name="looks" value="4" onclick="clickLooks">

function clickLooks() {
var nlRadios
nlRadios = document.getElementsByName("looks")
for (i=0 ; i<nlRadios.length ; i++) {
nlRadios[i].disabled = false;
}
}

I wrote this off the top of my head, so you might have to change it somewhat
to get it to work, but you should get the idea

Mike

"amith" <it*******@yahoo.co.in> wrote in message
news:90**************************@posting.google.c om...
hi,

i have some 10 radio buttons meant to take the rating from the user.
ex:

1 2 3 4 5 6 7 8 9 10
looks O O O O O O O O O O

1 2 3 4 5 6 7 8 9 10
features O O O O O O O O O O
..........
..........
..........

total score |______________|

submit button |_______|

the user has to select any one for each row (looks, features etc).
I have to calculate the total % of his rating.

leaving "looks" blank, he cannot go to the next( "features", in this
case) and so on. if he has left "looks" unchosen and tries to check
"features", i should prompt him until he checks a radio button in
"looks".

how can i do this?? on what event should i call a function that does
this??

please help

thanks in advance.

Regards,

Amith

Jul 20 '05 #2
You'd probably need an onClick event for each of the buttons in the
features group. E.g. (assuming the form is called "formname" and the
radio group is called "looks")

function checkLook(aRadioButton) {
var isChecked = false;
for (i = 0; i < document.formname.looks.length; i++) {
if (document.formname.looks[i].checked) isChecked = true;
}
if (!isChecked) {
alert("Please rate the looks first!");
aRadioButton.checked = false;
}
}

Then for each of the buttons in the features group, you'd do:

<INPUT TYPE="radio" NAME="features" VALUE="1"
onClick="checkLook(this)">
<INPUT TYPE="radio" NAME="features" VALUE="2"
onClick="checkLook(this)">

etc.

I haven't tested this, but you can try it out and tweak it.

it*******@yahoo.co.in (amith) wrote in message news:<90**************************@posting.google. com>...
hi,

i have some 10 radio buttons meant to take the rating from the user.
ex:

1 2 3 4 5 6 7 8 9 10
looks O O O O O O O O O O

1 2 3 4 5 6 7 8 9 10
features O O O O O O O O O O
..........
..........
..........

total score |______________|

submit button |_______|

the user has to select any one for each row (looks, features etc).
I have to calculate the total % of his rating.

leaving "looks" blank, he cannot go to the next( "features", in this
case) and so on. if he has left "looks" unchosen and tries to check
"features", i should prompt him until he checks a radio button in
"looks".

how can i do this?? on what event should i call a function that does
this??

please help

thanks in advance.

Regards,

Amith

Jul 20 '05 #3
I can't help with code but I would have thought the way to go is to have
user see only the first bit.
User fills it in and presses 'next' and the page refreshes to show the next
bit or gives and error if not filled in.

R
"Daniel Orner" <ci******@rpgclassics.com> wrote in message
news:77**************************@posting.google.c om...
You'd probably need an onClick event for each of the buttons in the
features group. E.g. (assuming the form is called "formname" and the
radio group is called "looks")

function checkLook(aRadioButton) {
var isChecked = false;
for (i = 0; i < document.formname.looks.length; i++) {
if (document.formname.looks[i].checked) isChecked = true;
}
if (!isChecked) {
alert("Please rate the looks first!");
aRadioButton.checked = false;
}
}

Then for each of the buttons in the features group, you'd do:

<INPUT TYPE="radio" NAME="features" VALUE="1"
onClick="checkLook(this)">
<INPUT TYPE="radio" NAME="features" VALUE="2"
onClick="checkLook(this)">

etc.

I haven't tested this, but you can try it out and tweak it.

it*******@yahoo.co.in (amith) wrote in message

news:<90**************************@posting.google. com>...
hi,

i have some 10 radio buttons meant to take the rating from the user.
ex:

1 2 3 4 5 6 7 8 9 10
looks O O O O O O O O O O

1 2 3 4 5 6 7 8 9 10
features O O O O O O O O O O
..........
..........
..........

total score |______________|

submit button |_______|

the user has to select any one for each row (looks, features etc).
I have to calculate the total % of his rating.

leaving "looks" blank, he cannot go to the next( "features", in this
case) and so on. if he has left "looks" unchosen and tries to check
"features", i should prompt him until he checks a radio button in
"looks".

how can i do this?? on what event should i call a function that does
this??

please help

thanks in advance.

Regards,

Amith

Jul 20 '05 #4
Mike wrote:
Have the HTML for the "features" <radio> buttons be disabled
<input type="radio" name="features" value="1" disabled>
<input type="radio" name="features" value="2" disabled>
<input type="radio" name="features" value="3" disabled>
<input type="radio" name="features" value="4" disabled>
That is a generally a bad idea. What about users without JavaScript?
It is much better to have the radio buttons disabled by JavaScript (if
it is supported) when the document has been loaded (in the `onload'
event handler of the `body' element):

<body ... onload="disableRadioButtons(name)">

The called function could be the code of the below clickLooks() with
adding having a named argument to define the value that should be assigned:

function disableRadioButtons(bDisable)
{
... = !!bDisable;
}

The double negation (!!) makes bDisable like an optional argument
since it always returns a boolean value. If bDisable is not provided,
`undefined', `null' aso. or `false', !!bDisable evaluates to `false'.

In the above event handler you would pass `true', a numeric value other
than 0 or a reference to an object. (Probably the first one or `1' :-))
Then, in the onclick event for "looks", make all the "features" enabled
<input type="radio" name="looks" value="1" onclick="clickLooks">
<input type="radio" name="looks" value="2" onclick="clickLooks">
<input type="radio" name="looks" value="3" onclick="clickLooks">
<input type="radio" name="looks" value="4" onclick="clickLooks">
clickLooks without parantheses as call operator is nothing but a
function statement. To make it a function call, write clickLooks().
function clickLooks() {
var nlRadios
It is good practice to end JavaScript statements with `;'.
nlRadios = document.getElementsByName("looks")
Besides,

var nlRadios = ...

does the trick, too. And you should check, as with any other object
and property, if document.getElementsByName is supported before you use
it:

if (document.getElementsByName)
... document.getElementsByName(...) ...

---> http://pointedears.de.vu/scripts/test/whatami

But you do not need the methods here.

var nlRadios = document.forms[...].elements["looks"];

will do the trick and it is both upwards and downwards compatible, where
`...' is the zero-based index of the form or the value of its `name' or
`id' attribute.
for (i=0 ; i<nlRadios.length ; i++) {
The counter variable is declared global here as the `var' keyword
is missing before it. That is bad style as it produces undesired
side effects, thus always use

for (var i = 0; i < nlRadios.length; i++)
{
// ...
}
nlRadios[i].disabled = false;
Note that if the `disabled' property is not supported,
but either nothing happens or you get script errors.
It is best to check it before:

if (typeof nlRadios[i].disabled != "undefined")
...
}
}

I wrote this off the top of my head, so you might have to change it somewhat
to get it to work, but you should get the idea
HTH
[Top post]


Please read and follow <http://www.netmeister.org/news/learn2quote2.html>

Besides, please remove the REMOVETHIS part of your `From:' header.
The sender's e-mail address must be valid and munging addresses is
a Bad Thing, most certainly forbidden by the rules of your Usenet
provider. There are other ways to get rid of spam that do not
annoy people that want to communicate with you, possibly providing
useful off-topic information.
PointedEars
Jul 20 '05 #5
JRS: In article <3F**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@web.de> posted at Wed, 26 Nov 2003 21:01:19 :-

Besides, please remove the REMOVETHIS part of your `From:' header.
The sender's e-mail address must be valid and munging addresses is
a Bad Thing, most certainly forbidden by the rules of your Usenet
provider. There are other ways to get rid of spam that do not
annoy people that want to communicate with you, possibly providing
useful off-topic information.

The address mb***************@skypoint.com is of legitimate format,
and may be one which Mike has permission from the owners of skypoint.com
to use.

Mail to that address should go to skypoint.com, and they may have
arranged suitable treatment for *R*********@skypoint.com ;
alternatively, Mike may have subscribed also to that address, in order
to keep his spam separate from the mail that is addressed as he asks.

Other than by communicating with skypoint, or with Mike, there is no way
in which you, as an outsider, can assess the situation reliably - and
you are known to know, or at least to have been told, that you have
failed to do so in my case.

Additionally, you cannot tell from his news article what anti-spam
methods are reasonably available to Mike. You can know only that he has
access to SuperNews using MSOE6; that implies nothing about how he
receives mail, and what processes he can reasonably be expected to
employ.

Mike's arrangements are, in fact, none of your business.
Under present circumstances it is unwise to provide an address in UseNet
News, particularly in headers, especially in From, for which delivery is
actually guaranteed - unless one has a permanently-operating high-
bandwidth connection to the Net, and is running appropriate software.

Indeed, given the capabilities of malware, it is unwise to allow the use
of a reliable E-address to any person in whose good faith and technical
ability one does not have complete confidence.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6
Dr John Stockton wrote:
Thomas 'PointedEars' Lahn [...]:
Besides, please remove the REMOVETHIS part of your `From:' header.
The sender's e-mail address must be valid and munging addresses is
a Bad Thing, most certainly forbidden by the rules of your Usenet
provider. There are other ways to get rid of spam that do not
annoy people that want to communicate with you, possibly providing
useful off-topic information.
The address mb***************@skypoint.com is of legitimate format,
and may be one which Mike has permission from the owners of
skypoint.com to use.


Correct, I oversaw the second SMTP server here. Sorry to Mike, my bad.

$ host -t mx skypoint.net
skypoint.com mail is handled by 50 ann.skypoint.net.
skypoint.com mail is handled by 100 minuet.skypoint.net.
$ telnet ann.skypoint.net smtp
Trying 199.86.32.19...
Connected to ann.skypoint.net.
Escape character is '^]'.
220 ann.skypoint.net ESMTP Sendmail 8.9.3/8.9.3; Thu, 27 Nov 2003
23:52:25 GMT
helo pointedears.de
250 ann.skypoint.net Hello [...], pleased to meet you
vrfy mb***************@skypoint.com
252 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
mail from:po*********@web.de
250 po*********@web.de... Sender ok
rcpt to:mb***************@skypoint.com
550 mb***************@skypoint.com... User unknown
quit
221 ann.skypoint.net closing connection
Connection closed by foreign host.
$ telnet minuet.skypoint.net smtp
Trying 199.86.32.2...
Connected to minuet.skypoint.net.
Escape character is '^]'.
220 minuet.skypoint.net ESMTP Sendmail 8.12.9/8.12.9; Thu, 27 Nov 2003
18:00:43 -0600 (CST)
helo pointedears.de
250 minuet.skypoint.net Hello [...], pleased to meet you
vrfy mb***************@skypoint.com
252 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
mail from:po*********@web.de
250 2.1.0 po*********@web.de... Sender ok
rcpt to:mb***************@skypoint.com
250 2.1.5 mb***************@skypoint.com... Recipient ok
quit
221 2.0.0 minuet.skypoint.net closing connection
Connection closed by foreign host.
$
Other than by communicating with skypoint, or with Mike, there is no
way in which you, as an outsider, can assess the situation reliably -
You are wrong.
Mike's arrangements are, in fact, none of your business.


http://www.interhack.net/pubs/munging-harmful/
PointedEars
Jul 20 '05 #7

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

Similar topics

2
by: Matt | last post by:
I have radio buttons on a form, and when the user makes the selection, it will trigger the event and send the form to the web server and print the selected value. In Case 1, I just use submit...
1
by: Robin Becker | last post by:
I have to make 2 from 6 radio buttons change the rest of a form and the remaining 4 to do the opposite change. I find that onchange differs between IE & Mozilla, but onclick appears at first sight...
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...
2
by: tshad | last post by:
I have 2 radio buttons: <asp:RadioButton ID="radDetail" GroupName="detailSummary" Text="Detail" checkedChanged="RadDetail_Clicked" runat="server" /> <asp:RadioButton ID="radSummary"...
16
by: marc_r_bertrand | last post by:
To all asp/db pros: The quiz code below works. But there is a problem when too many questions are answered (radio buttons clicked). I am not an asp pro. So, is there a pro out there or an...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
3
by: Andreas Wöckl | last post by:
HI Group! I have to programmatically create a user input form with various Checkbox and RadioButton lists - Beside every List I have to place an image button that is able to reset the...
1
rrocket
by: rrocket | last post by:
I have a page with radio buttons that either enable or disable textboxes depending on the radio button selection. When the user clicks submit the they are taken to a thank you page, but if they hit...
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.