Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form won't stop submission

Status
Not open for further replies.

cfgcjm

Programmer
Oct 30, 2007
21
US
I'm running a script on a form and it's not stopping the submission when it detects one of the cases and the variable is changed. It changes the classes and then submits/resets the form...any help?

Code:
function Check()
{
	//get the form fields
	var username = document.getElementById('username');
	var password1 = document.getElementById('password1');
	var password2 = document.getElementById('password2');
	var email = document.getElementById('email');
	var lname = document.getElementById('lname');
	var fname = document.getElementById('fname');
	var food = document.getElementById('food');
	var sport = document.getElementById('sport');
	var interest = document.getElementById('interest');
	var good=1;
	
	
	//validate
	if (username.value == "")
	{username.className = "invalidbox";
	 good=0;}
	
	if (email.value == "")
	{email.className = "invalidbox";
	good=0;}
	
	if (fname.value == "")
	{fname.className = "invalidbox";
	 good=0;}

	if (lname.value == "")
	{lname.className = "invalidbox";
	 good=0;}

	if (food.value == "")
	{food.className = "invalidbox";
	 good=0;}

	if (sport.value == "")
	{sport.className = "invalidbox";
	 good=0;}

	if (interest.value == "")
	{interest.className = "invalidbox";
	 good=0;}

	if (password1.value == "")
	{password1.className = "invalidbox";
	 good=0;}

	if (password2.value == "")
	{password2.className = "invalidbox";
	 good=0;}

	if (password1.value!=password2.value)
	{password1.className = "invalidbox";
  	 password2.className = "invalidbox";
 	 good=0;}

	if (good=0)
	{return false;}

	if (good=1)
	{return true;}
	
}
 
I'd say the problem lies in how you are calling the [tt]Check()[/tt] function rather than the internals of the function itself.

Code:
<input type="submit" value="Submit" onclick="return Check();" />

I'd hazard a guess you're missing the [tt]return[/tt] in there.

if not, write a quick function:
Code:
function blockSubmit(){
return false;
}

and call:
Code:
<input type="submit" value="Submit" onclick="return blockSubmit();" />

and see if that stops the form from submitting.


[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top