Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Javascript not working

I have this code:
function chk_vals() {
		if (ac == "c") {
			if (tp == "u") {
				document.st.action = "choose_cust.php";
			} else {
				document.st.action = "index.php";
			}
			return true;
		}
		if (document.st.firm.value == "" || document.st.faddr.value == "" || document.st.fcity.value == "" || document.st.fzip.value == "" || document.st.fst.value == "" || document.st.fphone.value == "" || document.st.pwd.value == "" || document.st.email.value == "" || document.st.pname.value == "") {
			alert("All form values required.");
			return false;
		}
		if (!document.st.agtc.checked) {
			alert("You must agreed to the terms & conditions before proceeding.");
			return false;
		}	
		if (tp == "u") {
			if (document.st.pwdr.value == "") {
				return true;
			}
		}		
		if (document.st.pwd.value != document.st.pwdr.value) {
			alert("Passwords do not match.");
			return false;
		}
		if(user == 2) {
			document.st.action = "testersn.php?tp=u";
		}	

		return true;
	}

Open in new window


and this:

<form method="POST" name="st" action="testers.php?tp=u" onSubmit="return chk_vals();">

The javascript variable ac (further up) is defined.

This is the form submit.
	<div class="row">
		<div class="col-xs-8 text-center col-xs-offset-2" style="padding-top:10px;"><input type="submit" value="Update Tester Data"><span style="padding-left:150px;"><input type="submit" value="Cancel" onMousedown="ac='c';"></span></div>
	</div>

Open in new window


The page displayed after submit is testers.php. I am trying to force it to testersn.php if the user is 2 (me).

Why does that part not work?

I can show the entire HTML page if need be, I'm trying to simplity things.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland 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 Richard Korts

ASKER

You made me look further:

tp = "u";
      function chk_vals() {
            if (ac == "c") {
                  if (tp == "u") {
                        document.st.action = "choose_cust.php";
                  } else {
                        document.st.action = "index.php";
                  }
                  return true;
            }
            if (document.st.firm.value == "" || document.st.faddr.value == "" || document.st.fcity.value == "" || document.st.fzip.value == "" || document.st.fst.value == "" || document.st.fphone.value == "" || document.st.pwd.value == "" || document.st.email.value == "" || document.st.pname.value == "") {
                  alert("All form values required.");
                  return false;
            }
            if (!document.st.agtc.checked) {
                  alert("You must agreed to the terms & conditions before proceeding.");
                  return false;
            }      
            if (tp == "u") {
                  if (document.st.pwdr.value == "") {
                        return true;
                  }
            }      

Since tp = u, it never GETS to that point. Of course I should have seen that, but you know how it goes.

Thanks,

Richard