Web Analytics Made Easy -
StatCounter print a content of a window - CodingForum

Announcement

Collapse
No announcement yet.

print a content of a window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • print a content of a window

    Dear members,

    I would like to know how to print data on the window i created with:
    myWin = window.open('', '', 'width=500,height=550,toolbar=no,scrollbars=no,status=no,scrollbars=no,menubar=no');

    On the window I have data from a form.
    I' ve used windw.prin() but it doesn' t work..

    Any help wiil be gratiful

  • #2
    Are you getting errors? Is nothing printing on the printer? You are not giving much to go by!

    With a little more information we might be able to help you out.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      See under my complete code:

      html>
      <head>
      <script language="JavaScript">
      <!--

      function printitdata()
      {

      window.print()
      }



      function showdata(f)
      {
      myWin = window.open('', '', 'width=500,height=550,toolbar=no,scrollbars=no,status=no,scrollbars=no,menubar=no');
      msg = '<html><head><title>Data</title></head><body bgcolor="white">';
      msg+= '<table border="0"><tr><td colspan="2" align ="center"><b>your data</b> </td></tr>';
      msg+= '<tr><td> Name : </td><td>' + f.myname.value + '</td></tr>';
      msg+= '<tr><td> first name: </td><td>' + f.myfname.value + '</td></tr>';
      msg+= '<tr><td> Adress : </td><td>' + f.myadress.value + '</td></tr>';
      msg+= '<tr><td> Zipcode: </td><td>' + f.Zip.value + '</td></tr>';

      msg+= '<tr><td><form><input type="button" value="Printdata" onClick="printit()"></td></tr>';
      msg+= '<tr><td><input type="button" value="Sluiten" onClick="window.close()"></from></td></tr></table>';
      msg+= '</body></html>';
      myWin.document.write(msg);

      }
      //-->
      </script>
      </head>



      <body bgcolor="#80FBFF">
      <form method="POST" action="Emailen.asp" name="myform">
      <Table border=1 width=70% cellspacing=0>
      <tr><td><input type="text" name="myname"></td></tr>
      <tr><td><input type="text" name="myfname"></td></tr>
      <tr><td><input type="text" name="myadress"></td></tr>
      <tr><td><input type="text" name="Zip"></td></tr>

      <tr><td><input type="button" value="zend" name="btnverzend" onClick="showdata(myform)"></td>
      </tr>

      </table>
      </form>
      </body>
      </html>

      Comment


      • #4
        Try this:
        Code:
        [size=1]<html>
        <head>
        <script type="text/javascript"><!--
            function showdata (f) {
                var myWin = window.open('', '', 'width=500,height=550,toolbar=no,scrollbars=no,status=no,scrollbars=no,menubar=no');
                var msg = '<html><head><title>Data</title></head><body bgcolor="white">';
                msg+= '<table border="0"><tr><td colspan="2" align ="center"><b>your data</b> </td></tr>';
                msg+= '<tr><td> Name : </td><td>' + f.myname.value + '</td></tr>';
                msg+= '<tr><td> first name: </td><td>' + f.myfname.value + '</td></tr>';
                msg+= '<tr><td> Adress : </td><td>' + f.myadress.value + '</td></tr>';
                msg+= '<tr><td> Zipcode: </td><td>' + f.Zip.value + '</td></tr>';
                msg+= '<tr><td><form><input type="button" value="Printdata" onClick="[b]window.print()[/b]"></td></tr>';
                msg+= '<tr><td><input type="button" value="Sluiten" onClick="window.close()"></from></td></tr></table>';
                msg+= '</body></html>';
                myWin.document.write(msg);
            } //-->
        </script>
        </head>
        
        <body bgcolor="#80FBFF">
        <form method="POST" action="Emailen.asp" name="myform"> 
            <table border="1" width="70%" cellspacing="0">
                <tr><td><input type="text" name="myname"></td></tr>
                <tr><td><input type="text" name="myfname"></td></tr>
                <tr><td><input type="text" name="myadress"></td></tr>
                <tr><td><input type="text" name="Zip"></td></tr>
                <tr><td><input type="button" value="zend" name="btnverzend" onClick="showdata(myform)"></td> 
            </tr> 
        </table>
        </form>
        </body>
        </html>[/size]
        The function printitdata was not found in the spawned window because it didn't live there. Since it's just a wrapper for the window.print() method, it's rather unnecessary, which can be used just like the window.close() method on your "Sluiten" button.

        Comment


        • #5
          try this:

          msg+= '<tr><td><form><input type="button" value="Printdata" onClick="window.print()"></td></tr>';
          Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

          Comment


          • #6
            I ve tried the code but it' s not working at and no message error..

            any one to help me

            Comment


            • #7
              aHA! Found it. I didn't realize earlier that it would be a problem, but indeed it is: you have to close() the document before you can print() the window. Here you go:
              Code:
              [size=1]<html>
              <head>
              <script type="text/javascript"><!--
                  function showdata (f) {
                      var myWin = window.open('', '',  'width=500,height=550,toolbar=no,scrollbars=no,status=no,menubar=no');
                      var msg = '<html><head><title>Data</title></head><body bgcolor="white">';
                      msg+= '<table border="0"><tr><td colspan="2" align ="center"><b>your data</b> </td></tr>';
                      msg+= '<tr><td> Name : </td><td>' + f.myname.value + '</td></tr>';
                      msg+= '<tr><td> first name: </td><td>' + f.myfname.value + '</td></tr>';
                      msg+= '<tr><td> Adress : </td><td>' + f.myadress.value + '</td></tr>';
                      msg+= '<tr><td> Zipcode: </td><td>' + f.Zip.value + '</td></tr>';
                      msg+= '<tr><td><form><input type="button" value="Printdata" onClick="window.print()"></td></tr>';
                      msg+= '<tr><td><input type="button" value="Sluiten" onClick="window.close()"></from></td></tr></table>';
                      msg+= '</body></html>';
                      [b]myWin.document.open();[/b]
                      myWin.document.write(msg);
                      [b]myWin.document.close();[/b]
                  } //-->
              </script>
              </head>
              <body bgcolor="#80FBFF">
              <form method="POST" action="Emailen.asp" name="myform"> 
                  <table border="1" width="70%" cellspacing="0">
                      <tr><td><input type="text" name="myname"></td></tr>
                      <tr><td><input type="text" name="myfname"></td></tr>
                      <tr><td><input type="text" name="myadress"></td></tr>
                      <tr><td><input type="text" name="Zip"></td></tr>
                      <tr><td><input type="button" value="zend" name="btnverzend" onClick="showdata(myform)"></td> 
                  </tr> 
              </table>
              </form>
              </body>
              </html>[/size]

              Comment


              • #8
                Thank you

                Choopernickel

                and every body it ' s working very well..I' m in the Netherlands.

                Thank to Atlanta

                Comment

                Working...
                X