i have created radio button on run time its value,id and name are same like 1,2,3… and so on, but i wanna interchange its values like this,
radio button is shown as,

after page load it would be like this and when i change radio it change its radio checked with the previous one
i am trying it my code is here,
var selection=new Array();
var allR = document.getElementsByTagName('input');
var a=0;
var b=0;
for(var i=0; i<allR.length; i++){
if(allR[i].type=='radio') { b++; }
if(allR[i].type=='radio' && allR[i].checked) { a++; }
}
var num=0;
alert(b);
for(var j=1;j<=b ;j++)
{
//for(var i=0; i<alr.length; i++){
if(document.getElementsByName('j').checked)
{
selection[num]=j;
num++;
alert(j);
//}
}
}
here i am getting total radio button in “b” variable and then putting the checked radio in array but cant swapping radio checked ???
hopes for your suggestions
EDITED:
html code would be like this,
<input type='radio' onclick='test(this.id);' name='Accounts' value='1' id=1 checked='checked'>1
<input type='radio' onclick='test(this.id);' name='Accounts' value='2' id=2>2
<input type='radio' onclick='test(this.id);' name='Accounts' value='3' id=3>3
<input type='radio' onclick='test(this.id);' name='Accounts' value='4' id=4>4
<br/>
<input type='radio' onclick='test(this.id);' name='Analytical Question' value='1' id=1>1
<input type='radio' onclick='test(this.id);' name='Analytical Question' value='2' id=2 checked='checked'>2
<input type='radio' onclick='test(this.id);' name='Analytical Question' value='3' id=3>3
<input type='radio' onclick='test(this.id);' name='Analytical Question' value='4' id=4>4
<br/>
<input type='radio' onclick='test(this.id);' name='Behavior Questions' value='1' id=1>1
<input type='radio' onclick='test(this.id);' name='Behavior Questions' value='2' id=2>2
<input type='radio' onclick='test(this.id);' name='Behavior Questions' value='3' id=3 checked='checked'>3
<input type='radio' onclick='test(this.id);' name='Behavior Questions' value='4' id=4>4
<br/>
<input type='radio' onclick='test(this.id);' name='Technical Questions' value='1' id=1>1
<input type='radio' onclick='test(this.id);' name='Technical Questions' value='2' id=>2
<input type='radio' onclick='test(this.id);' name='Technical Questions' value='3' id=3>3
<input type='radio' onclick='test(this.id);' name='Technical Questions' value='4' id=4 checked='checked'>4
now how to swap in this radio checked values ?
Check this FIDDLE
The code looks like this
YOUR MARKUP FIDDLE — Make sure the Name attributes have no spaces in between