How to create timer using JavaScript? How to set time interval for next call in JavaScript? Example

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        var inProcessCount =10;
        var myVar = setInterval(myTimer, 3000);
        function myTimer() {
            if (inProcessCount == 10) {
                alert("amit");
            }
            else {
                myStopFunction();
            }
        }

        function myStopFunction() {
            clearInterval(myVar);
        }
    </script>
</head>
<body>

</body>
</html>
Share:

How to count words in a string using JavaScript function? Example

<!DOCTYPE html>
<html>
<body>
    <input type="file" id="myFile" onchange="myFunction()">
    <script>
        function myFunction() {
            debugger
            var x = document.getElementById("myFile");
            var spiltFilename = x.files[0].name.split('.');
            var countFilenameChar = spiltFilename[0].length;
            if (countFilenameChar >= 2)
                alert("Filename should not exceed 200 characters");
        }
    </script>
</body>
</html>

Share:

How to find date differences between two date using JavaScript function? Example

<!DOCTYPE html>
<html>
   <body>
      <script>
         var dateFirst = new Date("11/26/2017");
         var dateSecond = new Date("11/28/2017");

         // time difference
         var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime());

         // days difference
         var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

         // difference
         alert(diffDays);
      </script>
   </body>
</html>
Share:

Thursday, 21 November 2019

How to create timer using JavaScript? How to set time interval for next call in JavaScript? Example

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        var inProcessCount =10;
        var myVar = setInterval(myTimer, 3000);
        function myTimer() {
            if (inProcessCount == 10) {
                alert("amit");
            }
            else {
                myStopFunction();
            }
        }

        function myStopFunction() {
            clearInterval(myVar);
        }
    </script>
</head>
<body>

</body>
</html>

How to count words in a string using JavaScript function? Example

<!DOCTYPE html>
<html>
<body>
    <input type="file" id="myFile" onchange="myFunction()">
    <script>
        function myFunction() {
            debugger
            var x = document.getElementById("myFile");
            var spiltFilename = x.files[0].name.split('.');
            var countFilenameChar = spiltFilename[0].length;
            if (countFilenameChar >= 2)
                alert("Filename should not exceed 200 characters");
        }
    </script>
</body>
</html>

Monday, 18 November 2019

How to find date differences between two date using JavaScript function? Example

<!DOCTYPE html>
<html>
   <body>
      <script>
         var dateFirst = new Date("11/26/2017");
         var dateSecond = new Date("11/28/2017");

         // time difference
         var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime());

         // days difference
         var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

         // difference
         alert(diffDays);
      </script>
   </body>
</html>

Popular

Total Pageviews

Archive