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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick returns true instead of false 1

Status
Not open for further replies.

mcghee31

IS-IT--Management
Dec 13, 2007
12
US
I am trying to use the onClick event in a form to test to see how to to prevent the form action form be perfromed.

I the onClick line:
Code:
<input type="submit" name="submit" value="Submit" onClick="testaction()" /></p>

The form starts with:

Code:
<form name="appts" method="post" action= "./include/index_insertDB.php" >

The form action is still being performed even though I stated return false in the js code. Why is this happening and how can I solve it?


Code:
       var errmsg("testing");  
       
       if(errmsg.length > 0) {
		alert(errmsg);
		return false;
	}
	else {
		return true;
	}
 
A simple fix [smile]
Code:
<input type="submit" name="submit" value="Submit" onClick="[!]return [/!]testaction()" /></p>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I wish I could help you to solve the issue, but one thing that I have learned is - in such cases, onsubmit works better than onclick. as, there are people who may submit by hitting enter, instead of clicking on the submit button.

One more thing. Have you tried changing your first line from

var errmsg("testing");

to

var errmsg = "testing";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top