I am trying to show modal on submit of form with some condition such as:
form have two text field, if one of them is filled then modal will be shown to user with some info and If both field are not filled then form will not bo going to submit
For this I did this but not getting success..
jsfiddle: jsFidle Link
<div id=modal-3 class=modal fade tabindex=-1 role=dialog aria-labelledby=myModalLabel aria-hidden=true>
<div class=modal-content>
<div class=modal-header>
<button type=button class=close data-dismiss=modal aria-hidden=true>×</button>
<h3 id=myModalLabel>Modal header</h3>
</div>
<div class=modal-body>
<p>do you want to save partial info</p>
</div>
<div class=modal-footer>
<button class=btn data-dismiss=modal aria-hidden=true id=finishNow>Finish Now</button>
<button class=btn btn-primary data-dismiss=modal id=doItLater>Do It Later</button>
</div>
</div>
</div>
<a href=#modal-3 role=button class=btn data-toggle=modal id=confirmButton>Confirm</a>
<form name=asd action=asdd name=formName id=refrenceSubmit >
<input type=text name=name11 id=nameField value=/>
<input type=text name=name22id=phoneField value=/>
<input type=submit name=name33value=Submit />
</form>
js:
$(function(){
$(#refrenceSubmit).submit(function(){
var inputFieldsCount=0;
$(this).find('input[type=text]').each(function(){
if($(this).val() != ) inputFieldsCount+=1;
});
if(!inputFieldsCount){
alert(You must fill in at least one field);
return false;
}else if(inputFieldsCount<2){
$('#confirmButton').click()
$('#showModelContainer').show()
$('#doItLater').click(click,function (e) {
$('#refrenceSubmit').submit()
}
});
return false;
}
});
});
EDITED JAVASCRIPT:
$(function(){
$(#submitAndContinue).click(function(evt){
var inputFieldsCount=0;
$('.refrenceSubmit').find('input[type=text]').each(function(){
if($(this).val() != ) inputFieldsCount+=1;
});
if(!inputFieldsCount){
alert(You must fill in at least one field);
evt.preventDefault();
}else if(inputFieldsCount<5){
$('#modal-3').modal('show');
evt.preventDefault();
}
else {
$('#modal-3').modal('hide'); //in-case is showing
}
});
$('#doItLater').on(click,function (e) {
$('#saveAndContinue').val('saveAndContinue');
$('.refrenceSubmit').submit();
});
});