jquery keyup function: enabling/disabling a textbox using keyup()

chaitanya90

I am trying to disable the textbox using keyup functionality. I have a TextArea and a Text Box. Now i use a keyup operation on backspace key, like if the length of content inside textarea is 3 it should disable the textbox. I also have an alert message which pops when the length of content in text area is 3. Code worked for the pop up but it doesnot worked for the textbox. What am i missing? Please help. Here is my code:

$('#comment').keyup(function() {
    if (event.which == 8) {
           var txt = $('#comment').val().length;
            if(txt == 3)
            {
                alert("backspace");
                $("#text1").attr("diasbled", "diasbled");
            }
        }

});

And here is the JSfiddle for the purpose.

nrsharma

You have some typo here it should be disabled not diasbled Try this

$('#comment').keyup(function () {
    var len = $(this).val().length;
    if (len >= 3) {
        $("#text1").prop("disabled", true);
    }
    else{
     $("#text1").prop("disabled", false);
    }
});

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery textbox validation using both on keyup and blur

From Dev

jQuery keyup function doesnt work?

From Dev

jquery - filter checkboxes in <ul> on textbox keyup

From Dev

Dynamic Jquery table constructed using ajax response data on textbox's each keyup event, not showing data of last ajax response (last keyup)

From Dev

How to use on select and keyup event on same function using jquery ?

From Dev

Run Jquery Function on Page Load and on Keyup

From Dev

Use keyup function in custom jQuery class

From Dev

Why is this JQuery 'keyup' function not populating a div?

From Dev

Create jQuery plugins including keyup function

From Dev

issue passing space with jquery On KeyUp function

From Dev

using ng-class on keyup function value

From Dev

CodeMirror using jQuery .keyup on editor textarea

From Dev

jQuery detecting changes on two elements using keyup()

From Dev

jQuery detecting changes on two elements using keyup()

From Dev

CodeMirror using jQuery .keyup on editor textarea

From Dev

Capture Tab KeyUp on a winrt textbox

From Dev

Keyup function into form element

From Dev

JavaScript on keyup function

From Dev

Keyup function into form element

From Dev

jQuery not detecting modifiers on keyup

From Dev

jQuery: 'if .change() AND .keyup()'

From Dev

Jquery keyup event not firing

From Dev

Delay on jquery keyup?

From Dev

jQuery - Reset value on keyup

From Dev

jquery on keyup trigger css

From Dev

jQuery .abort() on keyup event

From Dev

jQuery, keyup event not firing

From Dev

jQuery keyup working incorrectly

From Dev

Jquery keyup on page load