2

I a trying to set my group of checkboxes enabled when the value is not empty in my textbox (myinput) otherwise disable the group but it does not work as expected? what am i doing wrong?

html

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        function enable_cb() {
               if ($(this).val() != "" ) {
                $("input.group1").removeAttr("disabled");
            }
            else {
                $("input.group1").attr("disabled", true);
            }
        }

    </script>
</head>
<body>
    <form name="frmChkForm" id="frmChkForm">
    <input id="mytext" type="text" onkeydown="enable_cb(this);" />

    <input type="checkbox" name="chk9[120]" class="group1">
    <input type="checkbox" name="chk9[140]" class="group1">
    <input type="checkbox" name="chk9[150]" class="group1">
    </form>
</body>
</html>

2 Answers 2

3

You need to declare the input parameter on the method. 'this' is not automagically sent to the method.

   function enable_cb(textbox) { 
           if ($(textbox).val() != "" ) { 
            $("input.group1").removeAttr("disabled"); 
        } 
        else { 
            $("input.group1").attr("disabled", true); 
        } 
    } 
Sign up to request clarification or add additional context in comments.

1 Comment

Or better yet, assign the event listener from jQuery, and stick to $(this).
-2

have you tried just using $(".group1") or $(".group1 input")?

1 Comment

.group1 would give the exact same result as the current code. .group1 input would not work, as it would look for an input that is a child of a .group1 element. This is entirely unrelated to the problem.

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.