The following works fine:
$(function() {
EnableDisableButtons();
$('#TextBox1').keyup(function() {
EnableDisableButtons();
});
});
function EnableDisableButtons() {
var len = $('#TextBox1').val().length;
if (len == 0) {
$("#Button1").attr("disabled", "disabled");
}
else {
$("#Button1").attr("disabled", "");
}
}
But the following does not work at all:
var txt = $('#TextBox1');
$(function() {
EnableDisableButtons();
txt.keyup(function() {
EnableDisableButtons();
});
});
function EnableDisableButtons() {
var len = txt.val().length;
if (len == 0) {
$("#Button1").attr("disabled", "disabled");
}
else {
$("#Button1").attr("disabled", "");
}
}
The error it was throwing was " 'txt.val().length' is null or not an object". Can anyone help me on this.
thanks