0

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';
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by kainil
0
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

0

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

0

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>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.