i have tried code print option in div on webpage. not showing values entered in text box. please me code below or give references print div values values inside text box.
<!doctype html> <html lang="en"> <head> <title>10.1 investment portfolio details</title> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script> function printdiv(divname) { var inptext = document.getelementsbytagname("input")[0].value; var printcontents = document.getelementbyid(divname).innerhtml; var originalcontents = document.body.innerhtml; document.body.innerhtml = printcontents; document.getelementsbytagname("input")[0].value = inptext; window.print(); document.body.innerhtml = originalcontents; } </script> </head> <body> <input type="button" onclick="printdiv('printablearea')" value="print" /> <div id="printablearea"> <h1 style="margin-top:7px; text-align:center;margin-left: 47px;">10 assets investment</h1> <table border="1" id="10.1" name="10.1" style="margin-top:-8px" class="colsumportfolio"> <tr style="background-color:#d8a455; border-top-color: white; border-style: hidden hidden groove;font-size: 24px;font-size: 24px;"> <td colspan=6 style="border-right-style: hidden; font-weight:bold;">10.1 investment portfolio details</td> </tr> <tr> <th>particulars</th> <th>outstanding</th> <th>average</th> <th>interest & dividend earned</th> <th>income sale of investments</th> <th>yield</th> </tr> <tr> <td>investments total assets ratio</td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td> <input type=text> </td> </tr> <tr> <th colspan="6" style="text-align: left;background: white;color: black">investments in india usd</th> <!-- <td class="tdright"><input type=text id="10.1_2_1" name="10.1_2_1" title="qry"></td> <td class="tdright" ><input type=text id="10.1_2_2" name="10.1_2_2" title="qry"></td> <td class="tdright" ><input type=text id="10.1_2_3" name="10.1_2_3" title="qry"></td> <td class="tdright" ><input type=text id="10.1_2_4" name="10.1_2_4" title="qry"></td> <td><input type=text id="10.1_2_5" name="10.1_2_5" title="qry"></td> --> </tr> <tr class="totalcolor2"> <td> i. government securities</td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td> <input type=text> </td> </tr> <tr> <td> t-bills</td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td> <input type=text> </td> </tr> <tr> <td> central government securities</td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td> <input type=text> </td> </tr> <tr> <td> state government securities</td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td> <input type=text> </td> </tr> <tr class="totalcolor2"> <td> ii. other approved securities (as notified rbi)</td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td class="tdright"> <input type=text> </td> <td> <input type=text> </td> </tr> </table> </div> </body> </html>
i think trying print specific div
first of use document.getelementsbyid()
, in code.
add printcontents += inptext
before document.body.innerhtml = printcontents;
like this:
function printdiv(divname){ var originalcontents = document.body.innerhtml; var inptext = document.getelementsbytagname("input")[0].value; var printcontents = document.getelementbyid(divname).innerhtml; printcontents += inptext; document.body.innerhtml = printcontents; window.print(); document.body.innerhtml = originalcontents; }
Comments
Post a Comment