Re: toggle radio buttons by anchors..
Posted: Fri Feb 24, 2012 7:10 am
Can you be more specific? What do you want to achieve by doing this?
Were Back!
http://www.indie-resource.com/forums/
Code: Select all
<form>
<label>Radio1 <input type="radio" name="radioButton" value="1" /></label>
<label>Radio2 <input type="radio" name="radioButton" value="2" /></label>
<label>Radio3 <input type="radio" name="radioButton" value="3" /></label>
</form>
Code: Select all
<a href="javascript: selectRadio('button1'); void 0">Radio1</a>
<a href="javascript: selectRadio('button2'); void 0">Radio2</a>
<a href="javascript: selectRadio('button3'); void 0">Radio3</a>
<input type="radio" id="button1" name="radioButton" value="1" />
<input type="radio" id="button2" name="radioButton" value="2" />
<input type="radio" id="button3" name="radioButton" value="3" />
<script type="text/javascript">
function selectRadio(id)
{
var elem = document.getElementById(id);
var radioButtonGroup = elem.getElementsByTagName( elem.getAttribute('name') );
for( var i in radioButtonGroup )
{
radioButtonGroup[i].checked = false;
}
elem.checked = true;
}
</script>
Code: Select all
$('input[name="raceName"]').prop('checked', true);
Code: Select all
<input type="radio" name="class" id="class1" />
<input type="radio" name="class" id="class2" />
<label for="class1">Select class 1</label>
<label for="class2">Select class 2</label>