Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

print dialog window on form submit button

Posted on 2007-04-11
2
Medium Priority
?
593 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
dakyd earned 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

704 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