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

Discussion in 'Javascript' started by amith, Nov 5, 2003.

  1. amith

    amith Guest

    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
    amith, Nov 5, 2003
    #1
    1. Advertising

  2. amith

    Daniel Orner Guest

    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.

    (amith) wrote in message news:<>...
    > 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
    Daniel Orner, Nov 5, 2003
    #2
    1. Advertising

  3. amith

    Racket Guest

    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" <> wrote in message
    news:...
    > 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.
    >
    > (amith) wrote in message

    news:<>...
    > > 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
    Racket, Nov 7, 2003
    #3
  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.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
    Thomas 'PointedEars' Lahn, Nov 26, 2003
    #4
  5. JRS: In article <>, seen in
    news:comp.lang.javascript, Thomas 'PointedEars' Lahn
    <> 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 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 * ;
    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.
    Dr John Stockton, Nov 27, 2003
    #5
  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 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
    252 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
    mail from:p
    250 ... Sender ok
    rcpt to:
    550 ... 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
    252 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
    mail from:p
    250 2.1.0 ... Sender ok
    rcpt to:
    250 2.1.5 ... 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
    Thomas 'PointedEars' Lahn, Nov 28, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott D Johnson
    Replies:
    1
    Views:
    1,036
    Scott D Johnson
    Sep 27, 2006
  2. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    1,644
    rantingrick
    Jun 23, 2010
  3. Bill
    Replies:
    1
    Views:
    144
    Thomas 'PointedEars' Lahn
    Oct 23, 2003
  4. Dr. Leff
    Replies:
    3
    Views:
    276
    David Mark
    Oct 15, 2007
  5. Dr. Leff
    Replies:
    3
    Views:
    206
    David Mark
    Oct 15, 2007
Loading...

Share This Page