0
I’m learning php and tried something I do on Asp.net but it’s not rolling. I have a page that gets values from a previous page via _GET. In it I have radio type input that I want, that when clicking on a Ubmit, the selected radio turns red. the problem is that by clicking on Ubmit, the previously received value is lost, so the page does not load. How to do this without losing the received value?
the structure of the code is:
html head body form
Php code:
?php
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__ . '\0 - Apresentação\Controller\PerguntaController.php');
require_once(__ROOT__ . '\0 -Apresentação\Controller\RespostaController.php');
$Disciplina=$_GET["pergunta"];
$Perguntacontroller = new PerguntaController();
$retorno = $Perguntacontroller->Carregar($Disciplina);
$Respostacontroller = new RespostaController();
$x = 0;
while ($linha1 = mysqli_fetch_array($retorno)) {
$y=0;
$Pergunta = $linha1["pergunta"];
$Id[$x] = $linha1["Id"];
$certa[$x]=$linha1["certa"];
$retornoR = $Respostacontroller->Carregar($Id[$x]);
echo "$Pergunta<br /><br />";
while ($linha2 = mysqli_fetch_array($retornoR)) {
$Resposta = $linha2["Resposta"];
echo"<input type=\"radio\" name=$x value=$y >$Resposta <br /><br />";
echo"<input type=\"hidden\" name=$x value=$certa[$x]>";
$y++;
}
$x++;
}
?>
Java script code:
<script type="text/javascript">
document.getElementById("submit").onclick = function() {
var radios = document.getElementsByName("0");
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
$('input:radio').css('background','#000');
console.log("Escolheu: " + radios[i].value);
}
}
};
</script>
<input id="submit" type="submit">
Opa. 1. I didn’t put the html code so it wouldn’t be long. It has a form. 2. The button with id Submit ended up in the html I didn’t post. 3. About the input code Testarei. Thank you!
– Dyganar Campos
I took the form and everything worked out. Thanks!
– Dyganar Campos