0

I am building a form and alerting the user that they can not move to the next step until the input is successful

var location=document.getElementById("zip").value;
if(location==null || location==""){
    alert("Please insert a valid location!");
    return false;

}

If the user continues to the next step, the submit button is activated. If the user returns to this step, I want to hide the submit button only on this step if the same input is null. How can I do this using only javascript? The class of the submit button is 'btFinish'.

Thanks!

EDIT

I am using jQuery. I have tried

  $(btPrevious).click(function(e) {
                      $(btFinish).hide();
                    });

                  $(btNext).click(function(e) {
                      $(btFinish).show();
                    });

This hides the Finish button through the progression, but if there is an error in the input box, and the user clicks 'btNext', 'btFinish' will show even if the user must fix their input on the first step.

0

2 Answers 2

1

ok so from my understanding here you have two steps:

1) Zip must be filled in then user clicks to go to next step. 2) User can either submit finished or go back to the zip code step.

I would do something like this:

  $(btPrevious).click(function(e) {
      $(btFinish).hide();
  });

  $(btNext).click(function(e) {
      $(btFinish).show();
  });

  $('#zip').keyup(function(){
       if ($(this).val() === null || $(this).val() === ""){
            $(btFinish).hide();
       }
       else{
            $(btFinish).show();
       }
  });

this will prevent them from clicking on btFinish unless they have something written in the zip. I'm thinking that since they would hve to press the delete button, it should trigger the event handler. In the event that they can somehow elsewise clear the zip code, you could also check on blur or for whatever other event they can clear the box with.

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

Comments

0

I would suggest you are trying something like that:

var location = document.formname.inputname.value;


if(location == ""){

    alert("No Valid Location")
}

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.