Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Alert box when radio button selected?

Reply
Thread Tools

Alert box when radio button selected?

 
 
Nige
Guest
Posts: n/a
 
      12-10-2003
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
 
Reply With Quote
 
 
 
 
Vjekoslav Begovic
Guest
Posts: n/a
 
      12-10-2003
"Nige" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>


 
Reply With Quote
 
 
 
 
Nige
Guest
Posts: n/a
 
      12-10-2003
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
 
Reply With Quote
 
Nige
Guest
Posts: n/a
 
      12-10-2003
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
 
Reply With Quote
 
Nige
Guest
Posts: n/a
 
      12-10-2003
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
 
Reply With Quote
 
@SM
Guest
Posts: n/a
 
      12-10-2003
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 : (E-Mail Removed)
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
************************************************** ************


 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      12-10-2003
@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)".

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      12-11-2003
"Lee" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
<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.


 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      12-11-2003

"Nige" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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')>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to do an alert for a radio button value yawnmoth Javascript 4 10-20-2006 12:19 AM
ASP.NET Reset Radio Button in a group of Radio Buttons Scott D Johnson ASP .Net 1 09-27-2006 10:38 PM
alert box and problem with back button Ersin Gençtürk ASP .Net 3 10-18-2004 01:22 PM
set ReadOnly to radio button and check box Grey ASP .Net 1 05-31-2004 10:00 AM
Radio button List problem: How to find value of Radio button list's Selected Item using javascript?? Hiten ASP .Net Web Controls 1 05-26-2004 10:32 AM



Advertisments