How to select a switch / case statement with each click on the button

1

I would like to make a list of A-Z .

One detail, is based on breaking / dividing this list (gem) alphabet into parts:

Although my difficulty is in, after being clicked on the button, the same bring the list like this:

First click on the button - then first part will be loaded in this order.

A B W D AND F G H I

2nd click on the button - then it is loaded to second part.

J K L M N O P Q V

3rd click on the button - then it will end the third part with the rest of the alphabet.

R s T U W X Y Z

Each time I click the same button, I want to add the +1 variable.

For example: I have a count variable getting the value 0 initial, clicking this button will start the count++ to 1 and so on, executing each declaration block within stwich/case .

For details, note the logic below:

<script>
 window.onload = function(){

 var contador = 0;
 contador++;

 document.getElementById("conta").onclick = function(){
 document.getElementById("resultado").innerHTML=contador;


switch (contador){
 case "1":
 for ( i = 1; i < 9; i++ ){
 ler = String.fromCharCode(i+64);
 document.body.innerHTML += ler +"<br>";
 }
 break;
 case "2":
 for ( i = 1; i < 9; i++ ){
 ler = String.fromCharCode(i+64);
 document.body.innerHTML += ler +"<br>";
 }
 break;
 case "3":
 for ( i = 1; i < 8; i++ ){
 ler = String.fromCharCode(i+64);
 document.body.innerHTML += ler +"<br>";
 }
 break;
 alert("Ok! Fim de Listagem.\nRetome sua pesquisa.");
}
</script>
  

However, I have had difficulty making this selection every time I click the button.

     

Any tip, suggestion, and simplistic and / or practical examples, all to contribute, will be welcome as a response.

    
asked by anonymous 14.04.2016 / 02:38

1 answer

1

var c = 0
var result = document.getElementById('result');

function a() {
    result.innerHTML = '';
    switch (c.toString()) {
        case "1":
            for (i = 1; i < 9; i++) {
                ler = String.fromCharCode(i + 64);
                result.innerHTML += ler + "<br>";
            }
            break;
        case "2":
            for (i = 9; i < 17; i++) {
                ler = String.fromCharCode(i + 64);
                result.innerHTML += ler + "<br>";
            };
            break;
        case "3":
            for (i = 17; i < 27; i++) {
                ler = String.fromCharCode(i + 64);
                result.innerHTML += ler + "<br>";
            }
            break;
    }
    if (c == 3) {
        c = 0;
    }
    alert("Ok! Fim de Listagem.\nRetome sua pesquisa.");
}
<input type="button" onclick="a(c++);" value="click me">
<div id="result">
</div>
    
14.04.2016 / 02:57