0

I'm working on a form that has multiple stages inside tags.

The problem is when the user gets to the 3rd stage and they click continue , it resets them back to the 1st stage.

I believe this to be an issue with the java script although I'm not sure. If I change the if() part to something like if(phone = 11) (if the number entered has 11 digits) then it works , but it wont work with the validation.

Here is the java script to process the 3rd stage:

    function processPhase3() {
var validmail = ( /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/.test(email) ); //JUST A TEST
//phone.length = 11 && validmail

phone = _("Ctelephone").value;
mobile = _("Cmobile").value;
email = _("Cemail").value;
if (validmail) { 
_("phase3").style.display = "none";
_("phase4").style.display = "block";
_("progressBar").value = 99;
_("status").innerHTML = "Step 4";
} else {

}
}
Jamie Adamas
  • 11
  • 1
  • 6
  • not entiery sure , that how the code was when i got it – Jamie Adamas Aug 08 '14 at 17:07
  • The validmail boolean is false even when I provide a valid email. I also noticed that the button is submitting the form. This [related post](http://stackoverflow.com/questions/932653/how-to-prevent-buttons-from-submitting-forms) explains how to keep buttons from submitting forms. – Hamilton Lucas Aug 08 '14 at 17:07
  • @HamiltonLucas I dont understand how it could be submitting the form . Its the exact same button that is used on the first 2 stages . Also the boolean is true when you enter a correct email – Jamie Adamas Aug 08 '14 at 17:10
  • I'm not really sure why, but I think it's because the in the first two stages the form gets hidden before the event is done processing. I can get to step 4 by adjusting the button to not submit the form. – Hamilton Lucas Aug 08 '14 at 17:15
  • I added the return false to the button , and added an alert that tells you if the email is true or false but it still resets. If the if statement code is changed like i mentioned above then it works , but dosent work against the validation – Jamie Adamas Aug 08 '14 at 17:17
  • @HamiltonLucas You adjusted the button , How? also does the validation still work for it? – Jamie Adamas Aug 08 '14 at 17:18
  • The validation still works fine if you set the type of the button to "button". Right now, where you added the return false - you have it outside of the quotes, so it doesn't work. I also noticed that the way you did the alert, you're then assigning the result of the alert to the boolean - which is not what you want to do. Get rid of that alert. – Hamilton Lucas Aug 08 '14 at 17:35

1 Answers1

0

You need to adjust your button to not submit the form by setting the type of the button to "button".

Like this:

<button type="button" onclick="processPhase3()">Continue</button>

Hamilton Lucas
  • 419
  • 2
  • 5