ppa Posted November 25, 2005 Share Posted November 25, 2005 Hi I want to make the radio group of list disable and enable from the coding. But when i disable the radio group, only one option is disable.For example, let's say the radio group name is "Student" and there are 3 options in this group,say option1: M , option2: F and option3: NWhen i diable the radio group "Student", only the option1: M is disable but others enable. How can i do to disable all these options in the group?If you have any experience about this, please share with me. Thank you. Link to comment Share on other sites More sharing options...
hacknsack Posted November 25, 2005 Share Posted November 25, 2005 You have to loop through the radio group to work with each one. <script type="text/javascript"> function checkPets(cfield){ var p = document.forms['f1'].elements['Pet']; if(cfield.checked) { for(var i = 0; i < p.length; i++){ //remove the next line if you don't want them unchecked p[i].checked = false; p[i].disabled = true; } } else { for(var j = 0; j < p.length; j++){ p[j].disabled = false; } } } </script> </head> <body> <form name="f1"> <input type="radio" name="Pet" value="Cat"> Cat <br> <input type="radio" name="Pet" value="Dog"> Dog <br> <input type="radio" name="Pet" value="Snake"> Snake <br> <input type="checkbox" name="c1" onclick="checkPets(this)"> Don't Like Any Pets <b>Especially Snakes</b> </form> Thanks, Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now