user603007
user603007

Reputation: 11804

how to enable checkboxes based on textbox value?

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>

Upvotes: 2

Views: 1227

Answers (2)

awe
awe

Reputation: 22460

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); 
        } 
    } 

Upvotes: 3

zoran119
zoran119

Reputation: 11327

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

Upvotes: -2

Related Questions