PHP
OOPs
JavaScript
JQuery
Ajax
Codeigniter
Laravel
MySql
Node.js
Tutorials
C
C++
Json
Codeigniter 4
htaccess
wordpress
react.js
Blogs
Fundamental
Python
Search Your Query
×
--- Select Category ---
PHP
OOPs
JavaScript
JQuery
Ajax
Codeigniter
Laravel
MySql
Node.js
Tutorials
Blogs
Fundamental
Python
Most Popular Tutorials
What is Javascript
BOM (Browser object model)
DOM (Document object model)
Variable
Variable is empty or Not
Javascript output
Function
Events
Array
Get text value
Get Form field value
Pattern validation
Form validation
Checkbox validation
Inner Html form validation
Form validation on php server
Window and window location
Get Text Value
get javascript value in php
Date Format
Get php variable in javascript
Redirect page in javascript
Auto Refresh page and DIV
Get text value from dropdown
Clear Browser History
Get Checkbox value
select (Dropdown)
PopUp Contact Form
sidebar contact form
Show modal on page load
Auto calculate price GST
print html and Div content
Calculate Discount prince
Checked single or all checkbox
Auto Fill form data on click checkbox
Show subcategory (Dependent Dropdown)
country, state, city (Dependent Dropdown)
Image upload with preview image
Filter table data
Character Limit Validation
uploading file size validation
Special Character validation
multiple file upload (Add more)
function call after page load
Disable Submit Button After Form Submission
disable browser back button
Remove selected item from second & third dropdown list
Interview Question
Active Tab Menu
String methods
Tutorials Menus
What is Javascript
BOM (Browser object model)
DOM (Document object model)
Variable
Variable is empty or Not
Javascript output
Function
Events
Array
Get text value
Get Form field value
Pattern validation
Form validation
Checkbox validation
Inner Html form validation
Form validation on php server
Window and window location
Get Text Value
get javascript value in php
Date Format
Get php variable in javascript
Redirect page in javascript
Auto Refresh page and DIV
Get text value from dropdown
Clear Browser History
Get Checkbox value
select (Dropdown)
PopUp Contact Form
sidebar contact form
Show modal on page load
Auto calculate price GST
print html and Div content
Calculate Discount prince
Checked single or all checkbox
Auto Fill form data on click checkbox
Show subcategory (Dependent Dropdown)
country, state, city (Dependent Dropdown)
Image upload with preview image
Filter table data
Character Limit Validation
uploading file size validation
Special Character validation
multiple file upload (Add more)
function call after page load
Disable Submit Button After Form Submission
disable browser back button
Remove selected item from second & third dropdown list
Interview Question
Active Tab Menu
String methods
Share On Facebook
How to print html content and div using javascript?
File name : index.php
<!DOCTYPE html>
<html>
<title>Print form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<form method="post" action="" id="myfrm">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
<p align="center"><input type="button" onclick="myPrint('myfrm')" value="print"></p>
<script>
function myPrint(myfrm)
{
var printdata=document.getElementById(myfrm);
newwin=window.open("");
newwin.document.write(printdata.outerHTML);
newwin.print();
newwin.close();
}
</script>
</body>
</html>
Output :-
Personal information:
First name:
Last name:
File name : index.php
<html>
<head>
<script language="javascript">
function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}
</script>
<title>div print</title>
</head>
<body>
//HTML Page
//Other content you wouldn't like to print
<input name="b_print" type="button" class="ipt" onClick="printdiv('div_print');" value=" Print ">
<div id="div_print">
<h1 style="Color:Red">The Div content which you want to print</h1>
</div>
//Other content you wouldn't like to print
//Other content you wouldn't like to print
</body>
</html>
File name : index.php
<html>
<head>
<script>
function printDiv(divName){
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
</head>
<h1> do not print this </h1>
<div id='printMe'>
Print this only
</div>
<button onclick="printDiv('printMe')">Print only the above div</button>
</html>
File name : index.php
<html xmlns="http://www.ittutorial.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function PrintDiv() {
var divContents = document.getElementById("dvContents").innerHTML;
var printWindow = window.open('', '', 'height=200,width=400');
printWindow.document.write('<html><head><title>DIV Contents</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
}
</script>
</head>
<body>
<form id="form1">
<span style="font-size: 10pt; font-weight: bold; font-family: Arial">ASPSnippets.com
Sample page</span>
<hr />
<div id="dvContents" style="border: 1px dotted black; padding: 5px; width: 300px">
<span style="font-size: 10pt; font-weight: bold; font-family: Arial">Hello,
<br />
This is <span style="color: #0090CB">Mudassar Khan</span>.<br />
Hoping that you are enjoying my articles!</span>
</div>
<br />
<input type="button" onclick="PrintDiv();" value="Print" />
</form>
</body>
</html>
Share On Facebook
Previous
Next
Trending Tutorials
PHP
100+ Tutorials
PHP OOPs
80+ Tutorial
Codeigniter
100+ Tutorial
Laravel
100+ Tutorials
NODE.JS
100+ Tutorials
Javascript
100+ Tutorials
Download Live Projects
Review & Rating
0.0
/ 5
0
Review
5
(
0
)
4
(
0
)
3
(
0
)
2
(
0
)
1
(
0
)
Write Review Here
Review
Submit Review
×
Submit
Ittutorial
Ittutorial
Most Popular Tutorials
Show modal on page load
Get text value from dropdown
Auto calculate price GST
Interview Question
Date Format
multiple file upload (Add more)
Window and window location
Get text value
print html and Div content
Checkbox validation
Auto Refresh page and DIV
DOM (Document object model)
Active Tab Menu
Get php variable in javascript
Disable Submit Button After Form Submission
What is Javascript
Filter table data
Form validation on php server
Character Limit Validation
Checked single or all checkbox
Important Link
Core php Online Advance Tutorails and video Tutorials.
How to manage Session in php Tutorials.
More .......
upcomming codeigniter and angular js tutorials.
Click here to see More ...
Hello Friend Please Follow & Share Ittutorial.
×
Ittutorial
Please Follow and Share ittutorial.
Ittutorial