0

A form has a input field which would contain text values . There is a Save button as well for the form .

Requrement: The save button should get disabled as soon as Input field goes empty.

Problem: Javascript events like change,blur ,focus etc require loss of focus(that is a click outside) ,Hence save button would not get disabled simultaneously the input goes blank without user clicking outside of the field.

The closest being 'keypress' event .However the problem with this is,as soon as I try to make the field empty it checks for the input value and since it already has some value the condition check I have put to disalbe the button fails.

Refer the code below I've used STUDY_NAME is the input field id SAVE_DRAFT_TAB_GENERAL is the save button id.

Code :

    if($(STUDY_NAME)){
        $(STUDY_NAME).addEvent("keypress", function(){
            if($(STUDY_NAME).value == ''){
                $(SAVE_DRAFT_TAB_GENERAL).disabled = true;
            }else {
                $(SAVE_DRAFT_TAB_GENERAL).disabled = false;
            }
        });
    }
1
  • You are using JQuery in your question and in question tag line you mentioning javascript, it's misleading to responder, your question must be "JQuery event KeyPress" Commented Apr 29, 2016 at 7:08

1 Answer 1

1

You can try using KeyUp event which happens after the user types his values

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.