Cycle the selected radio buttons : RadioButton Radio « Form Control « JavaScript DHTML






Cycle the selected radio buttons

   

<html> 

<head> 
<title>Cycle</title> 
<script type="text/javascript"> 
function getSelectedButton(buttonGroup){ 
    for (var i = 0; i < buttonGroup.length; i++) { 
        if (buttonGroup[i].checked) { 
            return i; 
        } 
    } 
    return 0; 
} 

function cycle(form) { 
    var i = getSelectedButton(form.sizes); 
    if (i+1 == form.sizes.length) { 
        form.sizes[0].checked = true; 
    } else { 
        form.sizes[i+1].checked = true; 
    } 
} 
</script> 
</head> 
<body> 
<form> 
<input type="radio" name="sizes" value="3" checked="checked" />3
<input type="radio" name="sizes" value="2" />2
<input type="radio" name="sizes" value="0" />0
<input type="radio" name="sizes" value="1" />1
<input type="button" name="Cycler" value="Cycle Buttons" onclick="cycle(this.form)" />
</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.Finding the Selected Button in a Radio Group
11.An onClick event Handler for Radio Buttons
12.Get the radio button selection
13.Get the select radio button and its value