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

to cancel mouseclick 1

Status
Not open for further replies.

Rydel

Programmer
Feb 5, 2001
376
CZ
I have a submit button:

Code:
<input type=&quot;submit&quot; name=&quot;sub1&quot; onclick=&quot;checkIt()&quot;>

I'd like to cancel mouse click inside the function checkIt() in case some condition is true (e.g. some data is missing).

Thanks a lot in advance!
---
---
 
do you mean : you don't want the form to be submitted if there is an error ?
you don't need to cancle any click then !!!
just make your validation function return a boolean : true if everything went fine, false if some data is missing ...
another thing is : DO NOT call the function from the input type=submit !!! it won't work !!! this fires the function NOT when the form submits but when one clicks - this IS different (use it for display purpose for instance)
it has to be fired by onsubmit, in the FORM TAG :
<form .... onsubmit=&quot;javascript:return checkit()&quot;>
 
i don't think you can cancel the EVENT - but you can make the click to do nothig tho ;-)
for instance, say this function is fired with &quot;onclick&quot;
function foo() {
if (.... ) // something you want to check
do_something
}
so if the condition is FALSE, the function won't do anything : it's just like it'd never been called !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top