Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

print dialog window on form submit button

I have a javascript for a form that handles errors for things such as empty fields, unchecked radio buttons, etc.  However, on the submit button, if all criteria is met, then I need the print dialog window to come up before going to the action page.  The print dialog should print the form pages.  Any ideas how I can adjust what I have?  I also tried adding onClick="window.print()" to the submit button but it didn't work.  Again, the dialog has to appear only if all criteria is met in javascript below.

<script language="JavaScript">
      <!--//
      function valwpp(thisform) {
      
                                 myOption1 = -1;
                  for (i=0; i<thisform.newapp.length; i++) {
                  if (thisform.newapp[i].checked) {
                  myOption1 = i;
                  }
            }
            if (myOption1 == -1) {
                  alert("Please select either a New Application or Re-entry. (#1)");
                  return false;
            }
            if (document.formdata.licfname.value == "")
            {
                  alert("Please your first name. (#2)");
                  document.formdata.fname.focus();
                  return false;
            }
      return;
}

// -->
</script>


<form onSubmit="return valwpp(this)" action="formdata.cfm" name="formdata" method="post">
[fields]..
<input type="submit" value="Submit/Print" name="submit" src="images/submit.jpg"  >
</form>
ASKER CERTIFIED SOLUTION
Avatar of dakyd
dakyd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zvonko
Put the print() method at the end of validation function.
Like this:

<script language="JavaScript">
      <!--//
function valwpp(thisform) {
     myOption1 = -1;
     for (i=0; i<thisform.newapp.length; i++) {
         if (thisform.newapp[i].checked) {
            myOption1 = i;
         }
      }
      if (myOption1 == -1) {
         alert("Please select either a New Application or Re-entry. (#1)");
         return false;
      }
      if (thisform.licfname.value == ""){
          alert("Please your first name. (#2)");
          thisform.fname.focus();
          return false;
      }
      window.focus();
      window.print();
      return true;
}

// -->
</script>