Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Dear Programming
I want Change TimeOut In SetInterval Of JavaScript By User In RunTime
When Changing Value In Tag Input Of Html
But Below Code Not Working True
Please Help Me
By Regards Yarian


HTML
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="JS/jquery-2.1.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            
            var i = 0;
            var interval = 0;
            setInterval(function () {
                
                document.getElementById("WRDO").innerHTML = (i++).toString();
                
                document.getElementById("WRDO1").innerHTML = document.getElementById("DO").value.toString();
                
                interval = parseInt(document.getElementById("DO").value.toString());
                
                interval *= 1000;
                
            }, interval);
        });
    </script>
</head>
<body>
    <input type="text" id="DO" value="1" />
    <p id="WRDO"></p>
    <p id="WRDO1"></p>
</body>
</html>


What I have tried:

Hello Dear Programming
I want Change TimeOut In SetInterval Of JavaScript By User In RunTime
But Below Code Not Working True
Please Help Me
By Regards Yarian
Posted
Updated 2-Nov-16 22:54pm

This is a mess. Where did you get this code?
1. It is declared as HTML5 doctype but why at the same time
HTML
<html xmlns="http://www.w3.org/1999/xhtml">

2. There is this jQuery library, but you are using plain js code inside the jquery document.ready() method.
Do read out:
HTML Tutorial[^]; and
jQuery Tutorial[^]
Coming back to your question, if you want some action to take place (e.g changing the value interval to that in a text box) upon the happening of some event (e.g. changing of value in the text box), then you have to first bind that action to that event. As it is now, they are not bound. Check these out:
JS onchange Event[^]; or
jQuery .change()[^]
After you have updated the interval value, clear the current timer, then start the timer with a new interval, how to do this? Ask Google.
 
Share this answer
 
v4
try this

HTML
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head >
    <title></title>

    <script src="jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () { 
            funInterval();
        });
        var objInterval;
        function funInterval()
        {
            var i = 0;
            var num =  parseInt(document.getElementById("DO").value.toString());
            var interval =  num* 1000;
            objInterval = setInterval(function () {
                i++;
                document.getElementById("WRDO").innerHTML = i.toString();                 
                if(i  >= num )
                    clearInterval(objInterval);

            }, interval);
        }
        function changeInterval(obj)
        {
            var value = obj.value;
            clearInterval(objInterval);
            funInterval();
        }

    </script>
</head>
<body>
    <input type="text" id="DO" value="3" onchange="changeInterval(this);" />
    <p id="WRDO"></p>
    <p id="WRDO1"></p>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900