By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,520 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,520 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.