Reputation: 11804
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
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