javascript - text of input field is not printing while print using window.print() -
i have following html layout:
please fill form carefully: <input type="button" onclick="printdiv('print'); return false;" value="print" /> <div id="print"> <form action="" method="post"> <input type="text" name="user_name" value="" /> <input type="text" name="address" value="" /> <input type="text" name="date" value="14-06-2015" /> <input type="submit" value="submit" /> </form> </div>
and printdiv('print') function in head section of html page:
function printdiv(divname) { var printcontents = document.getelementbyid(divname).innerhtml; var originalcontents = document.body.innerhtml; document.body.innerhtml = printcontents; window.print(); document.body.innerhtml = originalcontents; }
but while printing form after filled-up, not showing text of input fields user entered in input box. predefined text (here date field) of input field of same form printing usual.
how can rewrite javascript function print text of input fields aslo?
that's because innerhtml not reflect changes user in input fields. see innerhtml example: user input doesn´t work, why?. better solution use css stylesheet control printable content.
@media print { body {display:none}; #print {display: block}; }
i on phone can't test it, may need update html , css don't have nested conflicting display rules
Comments
Post a Comment