Solved

print dialog window on form submit button

Posted on 2007-04-11
2
579 Views
Last Modified: 2008-02-01
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>
0
Comment
Question by:COwebmaster
2 Comments
 
LVL 19

Accepted Solution

by:
dakyd earned 500 total points
ID: 18892102
What about changing this:
  <form onSubmit="return valwpp(this)"

to:
  <form onSubmit="if (valwpp(this)) window.print(); else return false;"

and then at the end of your function, make sure it does:
  return true;  (instead of just return;)

All it does is look at the return value of your function.  If it's true, it does a window.print() .  Otherwise, it returns false to stop the form submission.  Hope that helps.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 18894373
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>


0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now