Why does my for loop come once?

Taykklan

I've got a code with a loop in my function..

Look a bit to my code please:

<!doctype html>
<html>
<head>
    <title>Test</title>
</head>
<body>
    Kies een tafel:
    <select id="tafels">
    <option value="1">Tafel 1</option>
    <option value="2">Tafel 2</option>
    <option value="3">Tafel 3</option>
    <option value="4">Tafel 4</option>
    <option value="5">Tafel 5</option>
    <option value="6">Tafel 6</option>
    <option value="7">Tafel 7</option>
    <option value="8">Tafel 8</option>
    <option value="9">Tafel 9</option>
    <option value="10">Tafel 10</option>
    </select>
    <input type="submit" id="submit" value="bereken" onclick="tafel23();">
    <div id="asd">
    </div>
    <script>
            function tafel23(){

        var value = document.getElementById('tafels').value;
        var value1 = parseInt(value);
        var teller = 0;

        for(teller = 1; teller <= 10; teller++){
            document.getElementById('asd').innerHTML=(value1 + " x " + teller + " = " + teller * value1 + "<br/>");
        }
        }
    </script>
</body>
</html>

My loop come onces when I click the submit button... But when I do innerHTML+= than it works, the whole loop is appearing, but when I press the submit button again and again, the loop is stacking.. So where I got the problem is, when I press the submit button that the loop will appear, but not again and again..

Thanks in advance guys!<3

pherris

Try clearing the div before you execute the loop:

function tafel23(){

    var value = document.getElementById('tafels').value;
    var value1 = parseInt(value);
    //you might check value1 for NaN here

    document.getElementById('asd').innerHTML=""; //clear it out
    for(var teller = 1; teller <= 10; teller++){
        document.getElementById('asd').innerHTML += value1 + " x " + teller + " = " + teller * value1 + "<br/>";
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does my loop rotate only once?

From Dev

why does my loop only run once?

From Dev

Why does my for loop only appear to run once?

From Dev

Why is my while loop iterating only once?

From Dev

Why my loop is just running once?

From Dev

Why does this bash for loop only iterate once?

From Dev

Why does the loop execute only once?

From Dev

Why does this loop execute only once?

From Dev

Why does setTimeout only print once in a loop?

From Dev

Why does the code come up with a NameError for two of my variables?

From Dev

Why is the 'if' condition in my while loop only checked once?

From Dev

Why does a connect by expression in a FOR loop, execute only once?

From Dev

Why does this loop more than once when a letters are entered?

From Dev

Why does a certain if statement only trigger once in a while loop?

From Dev

Why does this loop more than once when a letters are entered?

From Dev

Why does `i` become a string in my loop?

From Dev

Why does Angularjs hate my while loop?

From Dev

Why does my if statement create an infinite loop?

From Dev

Why does my code run into an infinite loop?

From Dev

Why does my program loop twice?

From Dev

Why does this @JsonIgnore fix my infinite loop?

From Dev

Why does this loop in my decryption function not work?

From Dev

Why does uint break my for loop?

From Dev

Why does my for loop go out of bounds?

From Dev

Why does this for loop ignore my variable?

From Dev

Why does my loop skip even steps?

From Dev

why does my program loop infinitely?

From Dev

Why does my loop iterate only twice?

From Dev

Why does my foreach loop stop?