0

I am dynamically creating a CheckBox and setting the disabled property like this:

chk.Disabled = false.

This renders the following HTML:

<input type="checkbox" disabled="disabled" .../>

On the click of the checkbox, I have a JS function that tries to enable it by doing a:

//get reference to the checkbox
chk.disabled = false;

This does not work. Any help?

1
  • It's a little unclear what you are trying to acheive. As a general UI rule though, clicking a disabled checkbox should not enable it, otherwise what's the point of disabling it? Commented Feb 5, 2009 at 20:49

3 Answers 3

1

If your checkbox is disabled, your onclick wont be called

Sign up to request clarification or add additional context in comments.

Comments

1

What you're trying to do is a bit odd. You're trying to enable a checkbox by clicking on the checkbox, which is disabled to start with. So, the onclick will not be registered until the checkbox is actually enabled.

Try the below to see what I mean.

<html>
<body>
    <input id="cb" type="checkbox" disabled="disabled" onclick="this.disabled=!this.disabled;" />
    <label for="cb">Click me</label>

    <input type="button" value="Click me instead!" onclick="cb.disabled=!cb.disabled;" />
</body>
</html>

Hope that helps you out.

Comments

0

How are you dynamically creating the check box?

Keep in mind that ASP.NET will change the name of the check box you give it, especially if you add it on the code behind.

What you need to do is send to your JS function the clientId, which is the id the HTML item will get when render.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.