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

Alert box when radio button selected?

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Nige" <uY***@ntlworld.com> wrote in message
news:br********************************@4ax.com...
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>
Jul 20 '05 #2

P: n/a
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
Jul 20 '05 #3

P: n/a
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
Jul 20 '05 #4

P: n/a
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
Jul 20 '05 #5

P: n/a
@SM
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:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
************************************************** ************
Jul 20 '05 #6

P: n/a
Lee
@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)".

Jul 20 '05 #7

P: n/a
"Lee" <RE**************@cox.net> wrote in message
news:br*********@drn.newsguy.com...
<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.
Jul 20 '05 #8

P: n/a

"Nige" <uY***@ntlworld.com> wrote in message
news:h3********************************@4ax.com...
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')>
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.