Link to home
Start Free TrialLog in
Avatar of Moti Mashiah
Moti MashiahFlag for Canada

asked on

Jquery keyup

Hi Guys,
can somebody tell how to write this jquery code:
I have a textbox and when user type in the textbox I would like to disable button and when something written in I would like to enable the button:

here is my example:
 $(document).ready(function () {
        $("#textmanufactureid").keyup(function () {
            if (this != "") {
                $("#activate-step-7").removeAttr('disabled');
            } else {
                $("#activate-step-7").attr('disabled', 'disabled');
            }
        });
    });

Open in new window

Avatar of Moti Mashiah
Moti Mashiah
Flag of Canada image

ASKER

Hi Guys,

I got the point it works now.

$(document).ready(function () {
        $("#textmanufactureid").keyup(function () {
            if ($(this).val() != "") {
                $("#activate-step-8").removeAttr('disabled');
            } else {
                $("#activate-step-8").attr('disabled', 'disabled');
            }
        });
    });

Open in new window


The issue actually was in the script file for some reason when I put this code on my script file "test.js" if doesn't work but when I put it on the html page itself it works.

you guys have idea why?
I can see the script file in the inspection at the browser.
Avatar of Siva Prasanna Kumar
Use Prop();

Sample code:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    
    $("input").keyup(function(){
   // alert(this.value.length);
    	if(this.value.length == 0)
        $("#button").prop('disabled', true);
        else
        $("#button").prop('disabled', false);
    });
});
</script>
</head>
<body>

Enter your name: <input id="textf" type="text" >
<button id="button" disabled> test </button>



</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yep basically it was kinda of what you said.
thanks,