Finding the Selected Button in a Radio Group : RadioButton Radio « Form Control « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » Form Control » RadioButton Radio 
Finding the Selected Button in a Radio Group
  
<HTML>
<HEAD>
<TITLE>Extracting Highlighted Radio Button</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function getSelectedButton(buttonGroup){
    for (var i = 0; i < buttonGroup.length; i++) {
        if (buttonGroup[i].checked) {
            return i;
        }
    }
    return 0;
}
function fullName(form) {
    var i = getSelectedButton(form.songs);
    alert("You chose " form.songs[i].value + ".");
}
function cycle(form) {
    var i = getSelectedButton(form.songs)
    if (i+== form.songs.length) {
        form.songs[0].checked = true
    else {
        form.songs[i+1].checked = true
    }
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<B>Select your favorite song:</B>
<P><INPUT TYPE="radio" NAME="songs" VALUE="A" CHECKED>A
<INPUT TYPE="radio" NAME="songs" VALUE="B" >B
<INPUT TYPE="radio" NAME="songs" VALUE="C" >C
<INPUT TYPE="radio" NAME="songs" VALUE="D" >D</P>
<P><INPUT TYPE="button" NAME="Viewer" VALUE="View Full Name..." onClick="fullName(this.form)"></P>
<P><INPUT TYPE="button" NAME="Cycler" VALUE="Cycle Buttons" onClick="cycle(this.form)"> </P>
</FORM>
</BODY>
</HTML>
           
         
    
  
Related examples in the same category
1.'defaultChecked' Example
2.Radio Button status Example
3.Check a Radio Button
4.Radio buttons in a form
5.Using the onPropertyChange Property
6.Radio action
7.Methods and Properties of the Radio Object
8.Determining the Value of the Selected Radio Button
9.Scripting a Group of Radio Objects
10.An onClick event Handler for Radio Buttons
11.Get the radio button selection
12.Get the select radio button and its value
13.Cycle the selected radio buttons
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.