how to print a Div content in javascript

By using this script we can print the content of a Div. It is working fine. We have to call this script like this: <button onclick=”printContent(print_div_id)”>Print</button> <script> function printContent(el) { var restorepage = document.body.innerHTML; var printcontent = document.getElementById(el).innerHTML; document.body.innerHTML = printcontent; window.print(); document.body.innerHTML = restorepage; } </script>

How to print a div content

<html> <head></head> <body> <style> .AP_CONTNT{width: 1000px;} .AP_HEAD{border: 1px solid;padding: 7px;background: bisque;} .AP_CONTNT1{border: 1px solid;padding: 7px;margin-top: 5px;background-color: cadetblue;} .AP_CONTNT2{border: 1px solid;padding: 7px;margin-top: 5px;background-color: cadetblue;} .AP_CONTNT2_B1{border: 1px solid;padding: 0px;background: white;} .AP_CONTNT2_BC1{border: 0px solid grey;padding: 7px;margin-top:5px;} .AP_CONTNT2_BC2{border: 0px solid;padding: 7px;margin-top:5px;} .AP_CONTNT2_BC3{border: 0px solid;padding: 7px;margin-top:5px;} .table1{border: 1px solid; width:100%;border-collapse:collapse;} .table1 tr td{border: 1px solid; } .table1 td{padding: 5px;} .div_btn{padding:5px;} … Read moreHow to print a div content

How to restrict input box to take only numbers

<input type=”text” name=”card_num” size=”4″ maxlength=”4″ onkeyup=”return isNumberKey(this);”> <script> function isNumberKey(e) { var numberRegex = /^[0-9]+$/; if(!numberRegex.test(e.value)) { e.value = e.value.replace(/\D/g, ”); } } </script>