troubleshooting Question

JavaScript - add a second onClick event to a form button?

Avatar of sabecs
sabecs asked on
JavaScriptjQuery
7 Comments1 Solution2618 ViewsLast Modified:
Hi,
how can I add a second onClick event to my form button?
I want checkFields() to run first and if returns true then redirect to process_payment.php page?

Thanks,

Andrew


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
  <script language="JavaScript" type="text/javascript" >
   //<!--
  var clickcount = 0;

   function checkFields(){
     if (clickcount == 0) {
       //count clicks 
       clickcount ++;
       return true;
     }
     else {
       alert("Transaction is in progress.");
       return false;
     }
   }
   //-->

   </script>

</head>

<body>

<form>
<input type="button" class="button green" onClick="location.href='process_payment.php?cartId=<?php echo $cookie;?>'" value="Process Order" >
</form>
</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros