9
I am using a jQuery Modal Dialog box to ask the user if they wish to submit the form or not.
However after the user clicks Dialog's Submit button, the form is not submitting.
If I then click the forms submit button again, it submits.
I am guessing this is a scope issue, I have seen some other posts about it but as yet have spent many hours with no luck. Any ideas on how to solve this?
Javascript
$(document).ready(function(){
var submitForm = $('#myform');
submit = false;
$("#confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
'Submit': function() {
$(this).dialog('close');
submit = true;
submitForm.submit();
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$("#confirm").parent().appendTo($("#myform"));
submitForm.submit(function() {
if (submit) {
return true;
} else {
$("#confirm").dialog('open');
return false;
}
});
});
HTML
<form id="myform" action="#" method="post">
<input type="text" name="check_me" />
<input type="submit" name="submit" value="Go!" />
</form>
<div id="confirm" style="display:none;">Please confirm that you want to submit</div>