Serialized Radio Button | Do not submit, if radio button is not selected

Below is my code, which serializes the list of radio button, these radio buttons are generated by PHP, and then it is printed on the client side using javascript.

What I need is,
after I choose all the radio buttons, and when i click on Submit button, I want it to “check if all the radio buttons are selected in the form“, if even a single/multiple radio buttons are not selected in the form, then i need a RED colour Star (mandatory symbol) next to each Not selected radio button

Then pass to another PHP which will save to DB. (this is working)

PHP:

    $mysqli=mysqli_connect('localhost','Uid','Pass','DB');

    $standard1 =  mysqli_real_escape_string($mysqli,trim($_POST["tclass"]));
    $section1 =   mysqli_real_escape_string($mysqli,trim($_POST["tsection"]));
    $SchoolID1 =   mysqli_real_escape_string($mysqli,trim($_POST["tschoolid"]));





            $query3="SELECT * FROM euser_student  WHERE  StudCourse='$standard1' and SchoolID='$SchoolID1'and StudentSection='$section1' order by StudentFirstName   ASC";
    $res3=mysqli_query($mysqli, $query3);
    echo '<table border="1">';
    for($i=0; $row=mysqli_fetch_assoc($res3); $i++) {
      $dat3 = $row['StudentFirstName'];
      $dat4 = $row['StudentRegID'];
      // data to ajax to display data in a div
      // we put the student's name in a hidden input
      echo "<tr>
        <td>" . $dat3 . " <input type='hidden' name='student[" . $i . "]' value='" . $dat3 . "'><input type='hidden' name='Reg[" . $i . "]' value='" . $dat4 . "'><input type='hidden' name='schoolid[" . $i . "]' value='" . $SchoolID1 . "'></td>
        <td><input name='present[" . $i . "]' type='radio' value='Present'>Present</td>
        <td><input name='present[" . $i . "]' type='radio' value='Absent'>Absent</td>
        <td><input name='present[" . $i . "]' type='radio' value='Leave'>Leave</td>
      </tr>";
    }



    echo '</table>';

Javascript:

 $(document).ready(function() {

      // radio buttons and input type Hidden data
      $('#myForm').submit(function(e) {
        e.preventDefault();
        $.ajax({
          url: 'save.php',
          data: $(this).serialize(),    // reads the data ...
          success: function(data) {
            alert("data Updated Successfully");
            window.location = 'login.html';

        });
      });

    }); 


Source: forms

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.