Auto-Scroll (every 5 seconds) window.setInterval(function() { var element = document.getElementById(“myDiv”); element.scrollTop = element.scrollHeight; }, 5000);
Category: JavaScript
How to use toFixed() for Float numbers in Javascript
The toFixed() method formats a number using fixed-point notation. function financial(x) { return Number.parseFloat(x).toFixed(2); } console.log(financial(123.456)); // expected output: “123.46” console.log(financial(0.004)); // expected output: “0.00” console.log(financial(‘1.23e+5’)); // expected output: “123000.00” OUTPUT: > “123.46” > “0.00” > “123000.00”
How to use column search in datatable when responsive is false
just add “$(“th”).show();” in the end of initComplete … , initComplete: function () { … $(“th”).show(); } , …
How to refresh a DIV content with Javascript
To reload a section of the page, you could use jquerys load with the current url and specify the fragment you need, which would be the same element that load is called on, in our below case #myDivId function updateDivContent() { $(“#myDivId”).load(window.location.href + ” #myDivId” ); }
Passing parameters to JavaScript files
You can assign an id to the <script> element and passing the arguments as data-* attributes. The resulting <script> tag would look something like this:
How to solve ajax.reload() not working for DataTables in JS File
If you use the reload in this way then it will probably not work. table.ajax.reload();
Javascript Refresh and CountDown Timer
<script type=”text/javascript”> function checklength(i) { ‘use strict’; if (i < 10) { i = “0” + i; } return i; } var minutes, seconds, count, counter, timer; count = 301; //seconds counter = setInterval(timer, 1000); function timer() { ‘use strict’; count = count – 1; minutes = checklength(Math.floor(count / 60)); seconds = checklength(count – minutes […]
How to Auto-Refresh Page with Javascript
<script type=”text/javascript”> function timedRefresh(timeoutPeriod) { setTimeout(“location.reload(true);”, timeoutPeriod); } window.onload = timedRefresh(300000); </script> Reference
Get and Use TextBox Values with Javascript
Here is the example code to get and use TextBox Values with Javascript:
