Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!