Alert box when radio button selected?

Discussion in 'Javascript' started by Nige, Dec 10, 2003.

  1. Nige

    Nige Guest

    Is it possible to create an alert box when a radio button is selected? I
    have a group of three, and I want a different alert for each one.


    --
    Nige

    Please replace YYYY with the current year
    ille quis mortem cum maximus ludos, vincat
    Nige, Dec 10, 2003
    #1
    1. Advertising

  2. "Nige" <> wrote in message
    news:...
    > Is it possible to create an alert box when a radio button is selected? I
    > have a group of three, and I want a different alert for each one.


    <form>
    <input name="myradio" value="1" type="radio" onclick="alert(this.value)">
    <input name="myradio" value="2" type="radio" onclick="alert(this.value)">
    <input name="myradio" value="3" type="radio" onclick="alert(this.value)">
    </form>
    Vjekoslav Begovic, Dec 10, 2003
    #2
    1. Advertising

  3. Nige

    Nige Guest

    In comp.lang.javascript, Nige wrote:

    >Is it possible to create an alert box when a radio button is selected? I
    >have a group of three, and I want a different alert for each one.


    Don't worry, sorted:

    <input type="radio" name="sign" value="planningtosign"
    onClick=alert('ABC')>


    --
    Nige

    Please replace YYYY with the current year
    ille quis mortem cum maximus ludos, vincat
    Nige, Dec 10, 2003
    #3
  4. Nige

    Nige Guest

    In comp.lang.javascript, Nige wrote:

    >>Is it possible to create an alert box when a radio button is selected? I
    >>have a group of three, and I want a different alert for each one.

    >
    >Don't worry, sorted:
    >
    ><input type="radio" name="sign" value="planningtosign" onClick=alert('ABC')>


    I spoke too soon.

    It works providing there are no spaces in the string argument - help!


    --
    Nige

    Please replace YYYY with the current year
    ille quis mortem cum maximus ludos, vincat
    Nige, Dec 10, 2003
    #4
  5. Nige

    Nige Guest

    In comp.lang.javascript, Nige wrote:

    >It works providing there are no spaces in the string argument


    Thanks Vjekoslav, it needed quotes!
    --
    Nige

    Please replace YYYY with the current year
    ille quis mortem cum maximus ludos, vincat
    Nige, Dec 10, 2003
    #5
  6. Nige

    @SM Guest

    Nige a ecrit :

    > In comp.lang.javascript, Nige wrote:
    >
    > >>Is it possible to create an alert box when a radio button is selected? I
    > >>have a group of three, and I want a different alert for each one.

    > ><input type="radio" name="sign" value="planningtosign" onClick=alert('ABC')>

    >
    > I spoke too soon.
    >
    > It works providing there are no spaces in the string argument - help!


    if you do only 'onclick="do that"'
    each time you click the radio you do that and no importance if it is secelcted
    so ...

    <input type=radio onclick="if(this.checked==true) alert('I am selected')
    else alert('I am not selected');">


    --
    **************************************************************
    St├ęphane MORIAUX : mailto:
    Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
    http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
    **************************************************************
    @SM, Dec 10, 2003
    #6
  7. Nige

    Lee Guest

    @SM said:
    >
    >Nige a ecrit :
    >
    >> In comp.lang.javascript, Nige wrote:
    >>
    >> >>Is it possible to create an alert box when a radio button is selected? I
    >> >>have a group of three, and I want a different alert for each one.
    >> ><input type="radio" name="sign" value="planningtosign" onClick=alert('ABC')>

    >>
    >> I spoke too soon.
    >>
    >> It works providing there are no spaces in the string argument - help!

    >
    >if you do only 'onclick="do that"'
    >each time you click the radio you do that and no importance if it is secelcted
    >so ...
    >
    ><input type=radio onclick="if(this.checked==true) alert('I am selected')
    >else alert('I am not selected');">


    You're thinking of checkboxes. Whenever you click on a radio button,
    it will be selected.

    also, "if(this.checked==true)" can be shortened to "if(checked)".
    Lee, Dec 10, 2003
    #7
  8. "Lee" <> wrote in message
    news:...
    <snip>
    >also, "if(this.checked==true)" can be shortened to "if(checked)".


    I don't think that I would recommend that shortcut. While it is the case
    that many (and most modern) browsers provide a custom scope handling
    mechanism for the event handling functions generated from event
    attribute string by the browser and, although those mechanisms differ
    considerably between browser implementations, that would result in the
    identifier "checked" being resolved as a property of the checkbox, there
    are browsers that do not provide any such scope handling mechanism.
    Opera <= 6 being an example (though I would be surprised if there were
    not others).

    The internally generated event handling functions in Opera 6 resolve
    scope exactly as if they were JavaScript defined function objects
    assigned to the event properties of the corresponding DOM nodes. As a
    result "checked", unqualified, is a reference to a (undefined?) global
    variable. However, the - this - keyword is required by the language to
    refer to the object to which the event handling function is attached
    (and called) as a method.

    My conclusion was that the best cross-browser support when writing even
    handling attribute string would be achieved by behaving as if there was
    no special scope handling mechanism associated with the resulting
    function and write the same code as would be needed in a function
    attached to the DOM node with JavaScript. So the object itself should be
    accessed as - this -, the form as - this.form -, and so on.

    Richard.
    Richard Cornford, Dec 11, 2003
    #8
  9. Nige

    Brian Guest

    "Nige" <> wrote in message
    news:...
    > In comp.lang.javascript, Nige wrote:
    >
    > >It works providing there are no spaces in the string argument

    >
    > Thanks Vjekoslav, it needed quotes!
    > --
    > Nige
    >
    > Please replace YYYY with the current year
    > ille quis mortem cum maximus ludos, vincat


    You can have spaces in the string... just do it this way:

    onClick="alert('AB CD EF')"

    instead of the way you had originally posted...

    onClick=alert('ABC')>
    Brian, Dec 11, 2003
    #9
    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. Samy
    Replies:
    5
    Views:
    690
  2. Scott D Johnson
    Replies:
    1
    Views:
    1,045
    Scott D Johnson
    Sep 27, 2006
  3. Hiten
    Replies:
    1
    Views:
    608
    Vidar Petursson
    May 26, 2004
  4. Verner Vaz
    Replies:
    1
    Views:
    91
    David Dorward
    Oct 17, 2004
  5. yawnmoth
    Replies:
    4
    Views:
    87
    nutso fasst
    Oct 20, 2006
Loading...

Share This Page