Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.
function setOn()
{
var theRadios = document.getElementsByName('RAM');
for(var i = 0; i < theRadios.length; i++)
{
theRadios[i].parentNode.className = 'off'; //Sets all spans class name to off
theRadios[i].onclick = function() //assigns a function to the onclick event of the radios
{
setOn();
}
if(theRadios[i].checked == 1) //if the radio button is checked then it will give the span that its in a class name of on
{
theRadios[i].parentNode.className = 'on';
}
}
}
onload = setOn;
<div name="component">
<span> web controls 1</span>
</div>
<div name="component">
<span> web controls 2</span>
</div>function setOn()
{
var components = document.getElementsByName('component');
for(var i = 0; i < components.length; i++)
{
var inputs = components[i].getElementsByTagName('input');
for(var k = 0; k < inputs.length; k++)
{
// Maybe validate if the input.type = radiobutton if you want to make sure
inputs[k].parentNode.className = 'off'; //Sets all spans class name to off
inputs[k].onclick = function() //assigns a function to the onclick event of the radios
{
setOn();
}
if(theRadios[k].checked == 1) //if the radio button is checked then it will give the span that its in a class name of on
{
theRadios[k].parentNode.className = 'on';
}
}
}
onload = setOn;
<div id="computersComponentChoose">
<fieldset><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" />
<label class="off"><input type="radio" value="RAM1" name="RAM" />512MB 667 DDR2 SDRAM - 1x512MB</label><br />
<label class="off"><input type="radio" value="RAM2" name="RAM" checked="checked" />512MB 667 DDR2 SDRAM - 2x256MB</label><br />
<label class="off"><input type="radio" value="RAM3" name="RAM" />1GB 667 DDR2 SDRAM - 2x512MB</label><br />
<label class="off"><input type="radio" value="RAM4" name="RAM" />1GB 667 DDR2 SDRAM - 1x1GB</label><br />
</fieldset>
</div>
function setOn()
{
var RadioRAM = document.getElementsByName('RAM');
var RadioHDD = document.getElementsByName('HDD');
// RAM
for(var i = 0; i < RadioRAM.length; i++)
{
RadioRAM[i].parentNode.className = 'off'; //Sets all spans class name to off
RadioRAM[i].onclick = function() //assigns a function to the onclick event of the radios
{ setOn(); }
if(RadioRAM[i].checked == 1) //if the radio button is checked then it will give the span that its in a class name of on
{ RadioRAM[i].parentNode.className = 'on'; }
}
// HDD
for(var i = 0; i < RadioHDD.length; i++)
{
RadioHDD[i].parentNode.className = 'off'; //Sets all spans class name to off
RadioHDD[i].onclick = function() //assigns a function to the onclick event of the radios
{ setOn(); }
if(RadioHDD[i].checked == 1) //if the radio button is checked then it will give the span that its in a class name of on
{ RadioHDD[i].parentNode.className = 'on'; }
}
}
onload = setOn;
function initComponents()
{
attachClickEvent(document.getElementsByName('RAM'));
attachClickEvent(document.getElementsByName('HDD'));
}
function attachClickEvent(radioArray)
{
for(var i = 0; i < radioArray.length; i++)
{
radioArray[i].onclick = toggle(radioArray[i]); // called each clicks
toggle(radioArray[i]); // direct call to style elements already selected
}
}
function toggle(input)
{
if(input.checked)
input.parentNode.className = 'on';
else
input.parentNode.className = 'off';
}
onload = initComponents;
1 to 11 of 11