Reputation: 13
I am using the submit function in Jquery to do some validation, if the validation is true it submits the form. However, I've added an 'are you sure' dialog. Can I pass back true or false from the dialog which would then submit the form as currently I'm stuck in a loop.
JQuery:
$(function(){
<!-- form validation -->
$("#form1").submit(function() {
//validation stuff
//Disable the submit button
$('#SubmitButton').attr('disabled', false);
// Only if true is returned from dialog??
return true;
}) });
html
<div id="testdialog" title="Please Check">
<p>Are you sure></p>
<div style="height: 30px; width:100px;"onclick="$('#testdialog').dialog('close');return true;">
Continue
</div>
<div style="height: 30px; width: 100px;" onclick="$('#testdialog').dialog('close');return false';">
Redo selection
</div>
</div>
Upvotes: 0
Views: 91
Reputation: 13
Thanks for the advice it near enough sorted the issue out. I had problems getting the onclick="confirmSubmit" to work and decided to use a listener instead.
$(function(){
$('#btnconf').click(function() {
$('#testdialog').dialog('close');
confirmed = true;
$("#form1").submit();
return true;
});
In the html I added id="btnconf" to the button.
Hey presto!! works a treat!. Thanks again!
Upvotes: 1
Reputation: 654
You would need to set a global/session variable that tells you if the user has already confirmed or not, something like this:
var confirmed = false;
var confirmSubmit = function() {
$('#testdialog').dialog('close');
confirmed = true;
$("#form1").submit();
return true;
}
$(function(){
<!-- form validation -->
$("#form1").submit(function() {
//validation stuff
//Disable the submit button
$('#SubmitButton').attr('disabled', false);
if (!confirmed) {
// Trigger the notification
}
// Only if true is returned from dialog??
return confirmed;
}) });
and the html:
<div id="testdialog" title="Please Check">
<p>Are you sure></p>
<div style="height: 30px; width:100px;"onclick="confirmSubmit">
Continue
</div>
<div style="height: 30px; width: 100px;" onclick="$('#testdialog').dialog('close');return false';">
Redo selection
</div>
</div>
Upvotes: 0