<html>
<head></head>
<title></title>
<body>
<p id="p1">This is para 1</p>
<input type="button" value="printonepara" onclick= "myFun('p1')">
<p id="p2">This is the para 2</p>
<input type="button" value="printonepara" onclick= "myFun('p2')">
<p id="pwhole">This is the whole para</p>
<input type="button" value="printonepara" onclick= "myFun1( )">
<script>
//To print the whole page
function myFun1( )
{
window.print( ); // = document.body.innerHTML
}
//To print the para 1 or para 2 only or particular section
function myFun( paravalue)
{
var backup = document.body.innerHTML; //backing up all content of the body
var para = document.getElementById(paravalue); // assigning content of specific id
document.body.innerHTML = para; // particular content assigned
window.print(); // printed out
document.body.innerHTML = backup; //return all
}
</script>
</body>
</html>
No comments:
Post a Comment