how to count the number 0to9 based on the number of digits in javascript

177 Views Asked by At

i am trying to implement number of digits for ex: if i give digit=3 in url, my output is 000 digit =5, my output is 00000 likewise it is coming but i need each and every digit should count 0 to 9 based on the digit value. for ex: if i give digit=3,it will come 000 and i need those three zero to count 0to9,0to9,0to9. i hope you all understand my question please help me this os for creating number of digit code but i need count code this is my html code

<html>
  <head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <style>
      div{
        display:inline-block;
      } 
    </style>
    <script>...</script> 
  </head>
  <body>   
     <div id="output" class="out"></div>
  </body>
</html>

this is js code

window.onload=function(){
    var output = document.getElementById('output');
    var i=1;    
    var param = getParameterByName("digit"); 
    var val="";
    while(i<=param)
    {

        if(!document.getElementById('timedrpact'+i))
        {
            var ele = document.createElement("div");
            ele.setAttribute("id","timedrpact"+i);
            ele.setAttribute("class","inner"); 
            ele.innerHTML="0";

            output.appendChild(ele);            
        }
        i++;
    }
};

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
1

There are 1 best solutions below

1
On

Here is the code. Once check it. Is this is what your requirement. If not let me know it. I do my best.

http://plnkr.co/edit/9ZBZuHsfkvOGjWPNq0ao?p=preview

HTML Code:

<body>
<h1>Hello Plunker!</h1>

<input type="text" id="input">
<button onclick="startCount()">Start Count</button>

<div id="output"></div>

<div id="test"></div>