www.webdeveloper.com
Results 1 to 14 of 14

Thread: printing from clientside

  1. #1
    Join Date
    Apr 2006
    Posts
    12

    printing from clientside

    I am showing the values from a database in a table format in a php page. i want to print the data on the page with a custom print button. without accessing the database data again. how it is possible?

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    Here is an example of a print button I included in an order form for one of my clients:
    Code:
      <p>Fill out this entire form,
      <script type="text/javascript">
      <!--//
      if (!window.print) document.write('print');
      else document.write('<input type="button" name="print" value="Print" ',
                          ' title="Click to open print dialog box." ',
                          ' onclick="window.print(); return true;">');
      //-->
      </script>
      it, and mail the two printed pages to:</p>

  3. #3
    Join Date
    Apr 2006
    Posts
    12

    printing

    Thank u very much. Now my problem is that window.print is printing everything on screen. i want only some informations like selected portions excluding header footer etc. ie, the values inside a particular area in the screen. which will be inside a table or like anything. so how can it be donw? shall i seperate the printable portion with some tags like <print> and end with <print>. then how can i do it?

  4. #4
    Join Date
    Dec 2004
    Posts
    8,637
    You need to use CSS to designate which parts of your markup are for display only.
    You can find out more about that in the CSS forum.

  5. #5
    Join Date
    Jun 2006
    Posts
    23
    hi, how do i do this, i should put this in the page and is that all. I am sorry for this question, it a shame, but...

    i copy this
    <script type="text/javascript">
    <!--//
    if (!window.print) document.write('print');
    else document.write('<input type="button" name="print" value="Print" ',
    ' title="Click to open print dialog box." ',
    ' onclick="window.print(); return true;">');
    //-->
    </script>
    and i paste it on the code of my html file, but i don see a button. I am sorry for the question, but can you help me??

    Thanks

  6. #6
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,277
    Quote Originally Posted by P099
    can you help me??
    Please post the URL for your page so we can see exacty what's going on.

  7. #7
    Join Date
    Jun 2006
    Posts
    23
    no, it isnīt still in the web, but it is on my PC, and the question is basic.

    With this javascript code i need to add a button?? and, if i do, what should the button say?? on click="?" <---- in the ? is where i donīt know. Or this code work alone, doesnīt it need something to do the action?

    Again i am sorry for this question, but i don get it

    Thanks

  8. #8
    Join Date
    Jun 2006
    Posts
    23
    problem fix


    Thanks again

  9. #9
    Join Date
    Jun 2006
    Posts
    23
    hello again

    I would like to add to this code a validation function but i need that if the validation is not good it wouldnīt print. I already have the validation function, that is not a problem, but i donīt know where to put it because I donīt undestand completly that if in this code.

    if you could tell me where should i put my function i would be gratefull.

    Thanks

  10. #10
    Join Date
    Dec 2004
    Posts
    8,637
    Am I supposed to guess at what code you've got.

  11. #11
    Join Date
    Jun 2006
    Posts
    23
    ok

    i have this code

    Code:
    <script type="text/javascript">
    <!--//
    if (!window.print) document.write('print');
    else document.write('<input type="button" name="print" value="Print" ',
    ' title="Click to open print dialog box." ',
    ' onclick="window.print(); return true;">');
    //-->
    </script>
    and somewhere in this code i want to call or put the function so i can validate my form and then print.

  12. #12
    Join Date
    Feb 2006
    Location
    Where I live, people get shot. I need to move.
    Posts
    634
    you would need to post the code that you already have, not just the bit of script that you have posted.

  13. #13
    Join Date
    Jun 2006
    Posts
    23
    Ok what i have is this code to print my page

    Code:
    <script type="text/javascript">
    <!--//
    if (!window.print) document.write('print');
    else document.write('<input type="button" name="print" value="Print" ',
    ' title="Click to open print dialog box." ',
    ' onclick="window.print(); return true;">');
    //-->
    </script>
    The page have some tables and a form. It goes like this

    Code:
     <td width="624"><div align="justify" class="Estilo1">
              <form name="form" method="post" action="procesar.php">
            <table cellspacing="0" class="Estilo1">
              <tr> 
                <td width="400">&nbsp;</td>
                <td width="624">&nbsp;</td>
              </tr>
              <tr> 
                <td>Nombres:</td>
                <td width="169"><input name="nombre" type="text"></td>
              </tr>
              <tr>  ....
    so i need to put my function "validate" some how so it will validate my form and if the validaton is not good it will not print.

    my validate function goes like this

    Code:
    <script language="JavaScript">
    
    function validate(form) {
      if (form.nombre.value.length < 4) {
        alert("Escriba por lo menos 4 caracteres en el campo \"Nombre\".");
        form.nombre.focus();
        form.nombre.select(); ....
    The code of javascript "validate" is not complite in this post and neither is the html code that shows the form, but it is long but similar to the part i write.

  14. #14
    Join Date
    Dec 2004
    Posts
    8,637
    You didn't show your entire function so no guarantees this will work as desired:

    <input type="button" name="print" value="Print"
    title="Click to open print dialog box."
    onclick="if(validate(this.form)){ window.print(); } else { alert('Print request ignored.'); }; return true;">

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles