Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

Add function to onClick confirm event button?

Hi,
                  I have a button with a confirm popup, but would like to validate some data first?
                  
                  How do I add the confirm and redirection to checkIfValid2 function, or can I just add  checkIfValid2() to onClick event on the button?

                  I hope that makes sense.

                  Thanks,

                  Andrew

			<div class="button_div postage_selected">
                        <input name="paypal_express_btn" type="button" 
                        onClick="if(confirm('You will now be redirect to PayPal to complete your Order, click OK to continue.')){location.href='process_payment.php?cartId=<?php echo $cookie;?>&payment_option=paypal_express'}" class="button blue" id="paypal_express_btn2" value="PayPal Express" />
                        </div>   

			function checkIfValid2(){
				if($('#shopping_cart').data('bValidator').validate())
					//add confirm and redirection here
			}

Open in new window

Avatar of John Smith
John Smith
Flag of Gibraltar image

Use

<input .... onClick="return checkIfValid2();" />

Open in new window


Then put the confirmation code in the checkIfValid function, do the redirect there, but return false if criteria hasn't been met.
Avatar of sabecs
sabecs

ASKER

Thanks for your help, but how do code the confirmation and redirection in the checkIfValid function?
			<div class="button_div postage_selected">
                        <input name="paypal_express_btn" type="button" 
                        onClick="return checkIfValid2();" class="button blue" id="paypal_express_btn2" value="PayPal Express" />
                        </div>   

			function checkIfValid2(){
				if($('#shopping_cart').data('bValidator').validate())
					if(confirm('You will now be redirect to PayPal to complete your Order, click OK to continue.')){location.href='process_payment.php?cartId=<?php echo $cookie;?>&payment_option=paypal_express'}";
return true;
			} else {
return false;
}

Open in new window

Avatar of sabecs

ASKER

Thanks again for your feedback but still can't get it to work.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial