Solved

print dialog window on form submit button

Posted on 2007-04-11
2
581 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

806 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