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

A

amith

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
 
D

Daniel Orner

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.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.
 
R

Racket

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 said:
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.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.

(e-mail address removed) (amith) wrote in message
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
 
T

Thomas 'PointedEars' Lahn

Mike said:
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.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.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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
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 (e-mail address removed) 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 *[email protected] ;
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.
 
T

Thomas 'PointedEars' Lahn

Dr said:
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 (e-mail address removed) 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 (e-mail address removed)
252 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
mail from:p[email protected]
250 (e-mail address removed)... Sender ok
rcpt to:[email protected]
550 (e-mail address removed)... 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 (e-mail address removed)
252 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
mail from:p[email protected]
250 2.1.0 (e-mail address removed)... Sender ok
rcpt to:[email protected]
250 2.1.5 (e-mail address removed)... 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top