Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem disabling a form field

Status
Not open for further replies.

greedyzebra

Technical User
Joined
Sep 5, 2001
Messages
140
Location
US
On my form I have two checkboxes, one with the value "yes" the other with the value "no." When one is clicked I want to disable both checkboxes. As is normally the case, the code to achieve this works perfectly in IE but it's too much for poor Netscape. What happens is that when "yes" is clicked, both boxes are disabled. But when "no" is selected, nothing is ever disabled (again I emphasize that this is NOT the case in IE, both are disable as I wish no matter which is clicked). Now I have made it my mission to disable only the "no" checkbox in Netscape if it is the last thing I do on this earth. Even this simple code does not work:

<input type=&quot;checkbox&quot; id=&quot;rsp1&quot; name=&quot;rsp1&quot; value=&quot;no&quot; onclick=this.disabled=true&quot;>

The identical code will disable the &quot;yes&quot; box, but not the &quot;no.&quot;

Incidentally, I was originally using radio buttons and had the same exact problem. I figured Netscape would not allow the disabling of all radio buttons in a group, so I switched to the checkboxes.

Any ideas are greatly appreciated.

Thanks,

Tom
 
Tested on IE 6 and NS 7

Put in Head tag
<script language=&quot;JavaScript&quot;>
function disableGroup(formName, groupName, booleanDisabled) {
for (var i=0; i<formName.elements.length; i++) {
if (formName.elements.name == groupName) {
formName.elements.disabled = booleanDisabled;
}
}
}
</script>

Put in your form

<input type=&quot;radio&quot; name=&quot;rsp1&quot; value=&quot;Yes&quot; onClick=&quot;disableGroup(this.form, 'rsp1', true)&quot;>
<input type=&quot;radio&quot; name=&quot;rsp1&quot; value=&quot;No&quot; onClick=&quot;disableGroup(this.form, 'rsp1', true)&quot;>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top