jQuery - Halt credit card process to display popUp question
Could someone tell me if its possible and if so put me on the right path on how to do so?
We have a checkout form to process credit card transaction.
On click of the submit button, I would like to check if a specific option is checked. If its checked, then go ahead and process credit card. If not checked, I would like to halt the process and display a pop up asking the user if they are sure they about the option.
Is it possible w开发者_JAVA技巧ith jQuery to halt the submitting of the form until this pop up is closed?
Yes. Add an onclick event to your submit button. If the onlcick returns false, the form will not submit. What you can do here is check for the option, and if you are going to submit, return true. If you need to do the popup first, don't return from the function until the popup is done (and then return true). This also allows you to cancel submission if you need to (user decideds during the popup not to submit) by returning false.
<input type="submit" value="submit" onclick="return popupcheck()" />
I'm not sure what kind of popup you are using, but here is some suggested pseudocode for the javascript:
function popupcheck(){
if(optionischecked){
return true //the form will submit
}
create/show popup
return false //the form will not submit (call popupisdone when the popup is done)
}
function popupisdone(){ //wire this up to be called when the popup is done
$("#ccform").submit() //unless there is some sort of cancel submit option in the popup
}
精彩评论