Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda