I've created a submit function to verify form inputs, and then, if desired (via checkbox), print as part of the submission process.
The issue is that when printing, the form submission never finishes. However, without printing, the form submits correctly.
<INPUT class=checkboxes id="Place order" onclick="return checkfields()" type=submit value=SUBMIT name="Place order">
The validation always seems to work correctly (as far as I know).
function checkfields() {
var missinginfo="Please fill in the following information";
var bres = true, qty=0, elem;
var tqty = document.getElementById('bottles').value;
if (tqty ==0){alert("No wine selected");bres=false;return bres;}
if (tqty %6 !=0){
alert("Orders need to be in 6 bottle packs. Please add " + (6 -(tqty %6)) + " bottles to your order");
bres=false;
return bres;
} //end if
for (i=1; i<30; i++) {
elem = document.getElementById('f'+i);
if(elem !=null){
if(elem.value== ""){
bres = false; missinginfo += "\n " + (document.getElementById('f'+i).name);
} //end if
} //end if
} //end for
if(!bres){alert (missinginfo );}
// end of validation here, print if checkbox checked
if(bres && document.getElementById('cprint').checked==true){window.print();}
document.getElementById('doc').value = "";
return bres;
}
Do you have any suggestions on how to fix this issue, or am I approaching it all wrong?