We help IT Professionals succeed at work.

Javascript error

Richard Korts
on
65 Views
Last Modified: 2019-02-11
I have this Javascript code:
function chk_vals() {
		alert("ac = " + ac);
		if (ac == "n") {
			document.st.action = "main.php";
			return true;
		}
		if (ac == "rm") {	
			alert("got to ac = rm");
			ne = document.getElementById("st").elements.length;
			alert ("ne = " . ne);
			nchkd = 0;
			for (i = 0; i < ne; i++){
				if (document.st.elements[i].type == "checkbox") {
					if (document.st.elements[i].checked) {
						nchkd++;
						break;
					}	
				}		
			}
			alert("nchkd = " + nchkd);			
			if (nchkd >= 1) {
				document.st.action = "remove_sels_fr_proj.php?pid=" + pid;
				return true;
			} else {
				alert("Please check at least one selection.")
				return false;
			}	
		}

Open in new window


<form method="post" name="st" action="load_proj.php" onSubmit = "return chk_vals();">

When I run it, it displays the first two alerts (up to & including alert("got to ac = rm");

No more alerts, & it goes to the default action, NOT the new action specified here.

What's wrong?
Comment
Watch Question

Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
If it is not displaying "alert("nchkd = " + nchkd)" then the 'break' on line 16 is probably taking it out of the function.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Richard KortsBusiness Owner / Chief Developer

Author

Commented:
zc2, I changed it as you suggested, it helped, but the alert on line 10 says undefined. I realized I was using the php concatenate, changed it to + so it now reads alert("ne = " + ne), and it works.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.