Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
How can I stop a radio button from unchecking after I push the submit button?

I'm trying to stop my radio button from automatically unchecking after I've pushed the submit button. Here I've created a function that is supposed to check the right radio button after the form was submitted, but that doesn't work. I'm also pretty sure there's a better way to solve this.

My code:

<html>
<head>
<meta charset="utf-8">
<title>Unbenanntes Dokument</title>
</head>

<body>
<h1>Arbeitsverhältnis:</h1> 
     <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <input type="radio" name="arbeitstyp" value="arbeiter" id="arbeiter"/>Arbeiter</input>
    <input type="radio" name="arbeitstyp" value="angestellter" id="angestellter"/>Angestellter</input>
    <input type="radio" name="arbeitstyp" value="lehrling" id="lehrling"/>Lehrling</input>
    <br><br>
    <button type="submit" name="ausgabe" value="ausgabe">Ausgabe</button>
</form>

    <br>
    <hr>
    <br>
    
    <script>
    function check() 
    {
        document.getElementsByName('arbeiter').checked;
    }
</script>
<?php
    if (isset($_POST['ausgabe'])){
    
        if($_POST['arbeitstyp'] == "arbeiter"){
            echo "Deine Arbeitszeit beginnt um 07:00 Uhr.";
            echo '<script>check();</script>';
        
        }
        else if($_POST['arbeitstyp'] == "angestellter"){
            echo "Deine Arbeitszeit beginnt um 08:00 Uhr.";
            echo '<script>check();</script>';
        }
        else if($_POST['arbeitstyp'] == "lehrling"){
            echo "Deine Arbeitszeit beginnt um 08:30 Uhr.";
            echo '<script>check();</script>';
        }
        else {
            echo "bitte wähle etwas aus.";
        }
    }
    ?>
    
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It will be cool to use flash session in PHP. There are 2 scenarios you want to display the selected radio button. Either after validation or after successful transaction.

Now if you use flash session in both logic, You can catch that flash session and display in your radio button.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda