javascript - Printing a div form with data to a page -
i have div (divcontents) containing form has several questions , input textboxes users enter answers. have button show , hide answers each input textboxes (the textboxes change colors when click button reveal/hide answers).
i've created print module me print div form:
function printcontent(){ var divno = document.getelementbyid("divpageno").value; var divcontents = document.getelementbyid(divno).innerhtml; var frame1 = document.createelement('iframe'); frame1.name = "frame1"; frame1.style.position = "absolute"; frame1.style.top = "-1000000px"; document.body.appendchild(frame1); var framedoc = frame1.contentwindow ? frame1.contentwindow : frame1.contentdocument.document ? frame1.contentdocument.document : frame1.contentdocument; framedoc.document.open(); framedoc.document.write('<html><head><title>div contents</title>'); framedoc.document.write('<style>h1 { display: none;}'); framedoc.document.write('h0 { font-size: 8.0rem; line-height: 8.0rem;}'); framedoc.document.write('</style>'); framedoc.document.write('</head><body>'); framedoc.document.write(divcontents); framedoc.document.write('</body></html>'); framedoc.document.close(); settimeout(function () { window.frames["frame1"].focus(); window.frames["frame1"].print(); document.body.removechild(frame1); }, 500); return false; }
the problem not show users' answer when try print. show textbox color changes. must missing obvious can't seen figure out is.
i found solution problem. current method allow me reconstruct screen form printable form, doesn't include form data entered user. requires additional javascript loop re-read form data elements printable form elements in example:
while (document.getelementbyid('word_id_' + word_page + '_' + id_start_num))
{
framedoc.document.getelementbyid('word_id_' + word_page + '_' + id_start_num).value = document.getelementbyid('word_id_' + word_page + '_' + id_start_num).value;
id_start_num++;
}
this works me.
Comments
Post a Comment