I have a radion box that has the values private public and friends but i cant't seem to get it to reset to the default value using javascript??
document.getElementById('emailsetting').checked='private';
I have a radion box that has the values private public and friends but i cant't seem to get it to reset to the default value using javascript??
document.getElementById('emailsetting').checked='private';
var a = document.getElementById('emailsetting');
b = a.length;
for(var i = 0; i < b; i++) {
if(a[i].checked) {
a[i].checked = false;
}
}
document.getElementById('emailsetting') is an array
.checked should be a bool not a value
mm thanks for that but not sure it is exactly what i am looking for as i am looking to reset the value to private if the value has been changed to public or friends
Try giving your selections values and use the reset function like below
<html>
<head>
<script>
function resetSelection()
{
var a = document.getElementById('emailsetting');
var b = a.length;
for(var i = 0; i < b; i++)
{
if(a[i].value == 'private')
{
a[i].checked = true;
}else
{
a[i].checked = false;
}
}
}
</script>
</head>
<body>
<form name='emailsetting'>
<input type='radio' name='selections' VALUE='private' CHECKED >Private
<input type='radio' name='selections' VALUE='public' >Public
<input type='radio' name='selections' VALUE='friends' >Friends
<input type='button' name='resetSel' value='Reset' onclick='javascript:resetSelection();'>
</form>
</body>
</html>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.