Click here to Skip to main content
15,069,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have defined a Print Function in Javascript where I will get "IDs" from the HTML page and add the innerHTML of the particular HTML Tag to the printing document. But for certain IDs the content is adding twice eventhough I am calling the ID once. How to resolve this?

function Print()
    var strContent = "<html><head></head><body>";
    var idHTMLTag = document.getElementById('myTable');
    var WinPrint ='', '', 'letf=400px,top=100px,width=800px,height=500px,toolbar=0,scrollbars=1,status=0,');
    if(get_tags[i].id == 'myTable')
                strContent = strContent + idHTMLTag.innerHTML;
    strContent = strContent + "</body></html>";

the HTML tag with ID 'myTable' is repeating twice in the "WinPrint" document. Please help me to resolve the issue.
Updated 27-Jun-14 0:25am
SRS(The Coder) 27-Jun-14 6:54am
First of all i will suggest to put an alert to the method and check if it is called correctly means once or not then we can check for the content it seems the content is being added twice to the 'strContent' variable.

Rather you can use 'jquery.PrintArea.js'to print a particular container HTML element's all content.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900