Re: Having a checkbox make something available when it's checked.



Jeff-

The Ctl00$... isn't necessary (as far as I know) on either of the browsers; that's the control hierarchy generated by .NET. getElementById should be able to find the control simply by it's Id attribute.

<div>
<input type="checkbox" onclick="javascript:document.getElementById('btnToCheckOut').disabled=!this.checked; return true;" />Accept?
<button id="btnToCheckOut" disabled="disabled">Checkout</button>
</div>

Tested in FF2, IE7, and Safari and works just fine.

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

I have a check box with javascript code attached to it that will allow
me to enable an 'accept' butten when the person has checked the box.
The code is:

input type="checkbox" name="checkbox"
onclick="javascript:document.getElementById('ctl00$MainPage$btnToCheck
out').disabled=!this.checked; return true; " />I

The code works fine in IE - the button becomes enabled when the check
box is clicked. But if Firefox it doesn't work.

Any thoughts?

TIA - Jeff.



.


Loading