Reputation: 3359
On ducument load i protecting my form from 'not safe' submit:
$("#my_form").submit(function(event){event.preventDefault();});
And after button click form are checked and should be submited but nothing happens:
$('#submit_b').click(function(){
if ($('input[name=site]:checked', '#my_form').attr('id') == 'E1')
{
//alert('ok' + $('input[name=site]:checked', '#my_form').attr('id') );
$('#my_form')[0].submit();
}
else
{
if (($('input[name=site]:checked', '#my_form').attr('id') !== 'E1') && ($('input[name=site]:checked', '#my_form').attr('id') !== 'OTR')) {
//alert('Not E ' + $('input[name=site]:checked', '#my_form').attr('id') );
$('#my_form')[0].submit();
}
else
{
if ($('input[name=site]:checked', '#my_form').attr('id') == 'OTR'){
//alert('other');
$('#my_form')[0].submit();
}
}
}
});
Upvotes: 0
Views: 60
Reputation: 1371
Undo the preventdefault just before submitting form.you can prevent default and undo it by using this approach.
function preventDefault(e) {
e.preventDefault();
}
//prevent default
$("#my_form").bind("submit", preventDefault);
//undo prevent default
$("#my_form").unbind("submit", preventDefault);
write undo code line just before submit form inside your validation loops. this will work
Upvotes: 0
Reputation: 589
You added a handler to form submit event that always prevents it.
If #submit_b
is an <input>
with type="submit"
located inside the form, you could do instead:
$('#my_form').submit(function(e){
if (/*conditions are not met*/) {
e.preventDefault();
return; //this will just abort
}
//additional operations or do nothing, which will submit the form
});
Upvotes: 0