I have a button that submits a payment for my website using a function that's defined in an external file. I want to add in an alert box popup for confirming or cancelling the function that's called with the button's onclick
. I'm familiar with javascript, however, I'm not sure of how exactly to call the function within another if it's defined externally.
What I have:
<script type="text/javascript">
var $jj = jQuery.noConflict();
$jj(document).ready(function () {
$jj('.alertbox').on('click', function () {
var _this = $jj(this);
$jj.confirm({
title: 'Confirm!',
content: 'Are you sure?',
buttons: {
confirm: function review.save(); {
},
cancel: function () {
}
}
});
});
});
</script>
Button phtml
:
<button type="submit" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Place Order')) ?>" class="button btn-checkout alertbox" onclick="review.save();" ><span><span><?php echo $this->__('Place Order') ?></span></span></button>
I know this does not work, as I get the following error:
Uncaught ReferenceError: review is not defined
at HTMLButtonElement.onclick
Do I get rid of the onclick
? Is there a more efficient way of doing this? Maybe using a form
and input
rather than button
?
$('#press').on('click', function(){ var val = validate(); if(val == true){ var r = confirm("Submit form!") var txt; if (r == true) { txt = "You pressed OK!"; //$( "#myform" ).submit(); //use this for submitting the form } else { txt = "You pressed Cancel!"; } alert(txt); //this line of code for test reasons } else{ alert("input fields empty"); } }); function validate(){ var val = true; var teste1 = $("#input1").val(); var teste2 = $("#input2").val(); if(teste1== "" || teste1 == null){ var val = false; //some css and jquery to change the input color } if(teste2 == "" || teste2 == null){ var val = false; //some css and jquery to change the input color } return val; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id = "myform" action="test.php" method="post"> <input type = "text" id ="input1" value = ""> <input type = "text" id ="input2" value = ""> <button id = "press" type="button">Click Me!</button> </form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.