I have this code:
let inicial = 0
let vPag = 3
const numeros = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
render()
function resultadoPag(pagina){
vPag = pagina.value;
render();
}
function proximo (){
if((inicial+1)*vPag < numeros.length)
inicial++;
render();
}
function anterior(){
if((inicial-1)*vPag >=0)
inicial--;
render()
}
function render (){
document.getElementById("lugar").innerHTML=''
for(let i = inicial*vPag; i < ((inicial+1)*vPag) && i < numeros.length && i >= 0;i++){
const ul = document.createElement('UL');
const numerosUl = document.createTextNode(numeros[i]);
const lugarElement = document.getElementById("lugar");
ul.appendChild(numerosUl);
lugarElement.appendChild(ul);
}
}
<html>
<div id='total'>
<button onClick="proximo()"> Próximo </button>
<div id="lugar"> Teste </div>
<button onClick="anterior()"> Anterior </button>
Deseja ver quantos elementos por vez
<select id='select' onchange="resultadoPag(this)">
<option value="3" >3</option>
<option value="5" >5</option>
<option value="10" >10</option>
</select>
</div>
</html>
What's the idea: It's that every time I change the value in select
, it goes back to the starting point with the modifications.
Example: select
is showing on 3 and on the second page, then:
- 4
- 5
- 6
When I select the value 5 in select
, it should return the home page with:
- 1
- 2
- 3
- 4
- 5
In the current case of the code, if I change to 5, it will be:
- 4
- 5
- 6
- 7
- 8
Could someone help me?