-3
I am making a simple program, however I am with an error at the time of displaying the information, the following occurs, after generating the loop I click on one of the buttons, and regardless of the button I click, is always displayed the first result. If anyone knows a way to resolve this, and wishes to share, it would be of utmost importance.
<div id="busca">
<h1>Olá, seja bem-vindo</h1>
<p id="informativo">Digite um número abaixo</p>
<form method="post" action="">
<input id="cpf_processo" type="text" size="50" name="num_usuario" required="required"
placeholder="Digite aqui">
<input id="consultar" type="submit" name="vis_numero" value="CONSULTAR">
<br>
</form>
</div>
</body>
</html>
<script type="text/javascript">
function visTabela(id) {
var numero = document.getElementById("numero");
var informativo = document.getElementById("informativo");
if (numero.style.display === "none") {
numero.style.display = "revert";
} else {
numero.style.display = "none";
informativo.style.display = "revert";
}
}
</script>
<?php
$numUsuario = filter_input(INPUT_POST, 'num_usuario', FILTER_SANITIZE_STRING);
$visNumero = filter_input(INPUT_POST, 'vis_numero', FILTER_SANITIZE_STRING);
if ($visNumero == true) {
for ($i = 0; $numUsuario > $i; $i++) {
$infor = "<div id='informativo' style='display: block'> clique no botão acima</div> <br>";
$mosNum = "<div id='numero' style='display: none'>O número do botão: $i </div>";
$botao = "<button style='margin-top: 4%' onclick='visTabela()'>Mostrar número</button> ";
echo "$botao";
echo "$infor";
echo "$mosNum";
}
}
What exactly do you want? explain in more detail, first of all suggest see how to create a [Mre] and How to make a good question?, edit your question, add details and clarifications, your attempts, the step-by-step of how it works and/or was meant to work, among others..
– gleisin-dev
Usually in this kind of thing you need to send the ID and you open the right one, in case you’re not using the id for anything.
– Gustavo Guimarães