Connecting Tech Pros Worldwide Forums | Help | Site Map

Alert box when radio button selected?

Nige
Guest
 
Posts: n/a
#1: Jul 20 '05
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

Vjekoslav Begovic
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Alert box when radio button selected?


"Nige" <uYYYY@ntlworld.com> wrote in message
news:br8etv8v7399elp3j15sfe6qhct080sauj@4ax.com...[color=blue]
> 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.[/color]

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


Nige
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Alert box when radio button selected?


In comp.lang.javascript, Nige wrote:
[color=blue]
>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.[/color]

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

re: Alert box when radio button selected?


In comp.lang.javascript, Nige wrote:
[color=blue][color=green]
>>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.[/color]
>
>Don't worry, sorted:
>
><input type="radio" name="sign" value="planningtosign" onClick=alert('ABC')>[/color]

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

re: Alert box when radio button selected?


In comp.lang.javascript, Nige wrote:
[color=blue]
>It works providing there are no spaces in the string argument[/color]

Thanks Vjekoslav, it needed quotes!
--
Nige

Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat
@SM
Guest
 
Posts: n/a
#6: Jul 20 '05

re: Alert box when radio button selected?


Nige a ecrit :
[color=blue]
> In comp.lang.javascript, Nige wrote:
>[color=green][color=darkred]
> >>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.[/color]
> ><input type="radio" name="sign" value="planningtosign" onClick=alert('ABC')>[/color]
>
> I spoke too soon.
>
> It works providing there are no spaces in the string argument - help![/color]

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:stephaneOTER-MOImoriaux@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
************************************************** ************


Lee
Guest
 
Posts: n/a
#7: Jul 20 '05

re: Alert box when radio button selected?


@SM said:[color=blue]
>
>Nige a ecrit :
>[color=green]
>> In comp.lang.javascript, Nige wrote:
>>[color=darkred]
>> >>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')>[/color]
>>
>> I spoke too soon.
>>
>> It works providing there are no spaces in the string argument - help![/color]
>
>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');">[/color]

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

Richard Cornford
Guest
 
Posts: n/a
#8: Jul 20 '05

re: Alert box when radio button selected?


"Lee" <REM0VElbspamtrap@cox.net> wrote in message
news:br8apb02n5g@drn.newsguy.com...
<snip>[color=blue]
>also, "if(this.checked==true)" can be shortened to "if(checked)".[/color]

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.


Brian
Guest
 
Posts: n/a
#9: Jul 20 '05

re: Alert box when radio button selected?



"Nige" <uYYYY@ntlworld.com> wrote in message
news:h3fetvg393mkv7ghfrjgubdburjtujp00g@4ax.com...[color=blue]
> In comp.lang.javascript, Nige wrote:
>[color=green]
> >It works providing there are no spaces in the string argument[/color]
>
> Thanks Vjekoslav, it needed quotes!
> --
> Nige
>
> Please replace YYYY with the current year
> ille quis mortem cum maximus ludos, vincat[/color]

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


Closed Thread