Alert box when radio button selected?

N

Nige

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

Vjekoslav Begovic

Nige said:
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>
 
N

Nige

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')>
 
N

Nige

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!
 
@

@SM

Nige a ecrit :
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:[email protected]
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
**************************************************************
 
L

Lee

@SM said:
Nige a ecrit :


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

Richard Cornford

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

Brian

Nige said:
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')>
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top