Modal box when submitting the form
I want to show modal box confirmation before submitting the form. how can I do that?
I have a code like below, which will get data in input and will check in database, if data is already exist. but how can I have a confirmation modal when condition is false and form is ready to submit?
- $(function(){
- $('#my-submit-button').on('click', function(){
- $.post("http://domain.com.ph/portal/reports/home_members/ajax_chassis_no/",
- $('#my-form').serialize(),
- function(result){
- if($.trim(result) != ''){
- alert(result);
- } else {
- //No error, submitting the form now to its action "save.php"
- $('#my-form').submit(); <-------- Must have confirmation before submit the form.
- }
- });
- //form will not wait for the ajax response and will be submitted, so by default stop submitting the form
- return false;
- });
- });
Here's modal box I made.
- <script type="text/javascript">
$('#modal-dialog').on('show', function() {
var link = $(this).data('link'),
confirmBtn = $(this).find('.confirm');
})
$('#btnYes').click(function() {
// handle form processing here
alert('submit form');
$('#my-form').submit();
});
</script>