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

asked on

Jquery

Hi Guys,
I have keyup method and I disable button when textbox is empty look at the code below:
the issue I have here is when user enter space it is also enable for them the button. How do I give statement to allow user to enable the button just when the put characters in the textbox no spaces.?
 
$(document).ready(function () {
    $("#Upctextid").keyup(function () {
        if ($(this).val() != " ") {
            $("#activate-step-2").removeAttr('disabled');
        } else {
            $("#activate-step-2").attr('disabled', 'disabled');
        }
    })
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jim Riddles
Jim Riddles
Flag of United States of America 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
Avatar of Moti Mashiah

ASKER

Thank you very much I used the keyup with you code and it works perfectly.

I didn't use blur as it is didn't work in a time user type in the box

 $("#Upctextid").keyup(function () {
        //get the current fields DOM element
        var myVal = $(this)[0];
        //strip all of the spaces from the field's value and see if it is empty
        if (myVal.value.replace(/ /g, '') === "") {
            $("#activate-step-2").prop('disabled', 'disabled');
        } else {
            $("#activate-step-2").prop('disabled', false);
        }
    });