简体   繁体   English

序列化单选按钮| 如果未选中单选按钮,则不提交

[英]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. 下面是我的代码,该代码序列化了单选按钮的列表,这些单选按钮是由PHP生成的,然后使用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. 然后传递到另一个将保存到数据库的PHP。 (this is working) (这正在工作)

PHP: 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: 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';

        });
      });

    }); 

You want something like jQuery validation plugin. 您想要类似jQuery验证插件的内容。 http://jqueryvalidation.org/ http://jqueryvalidation.org/

Checkout demo here http://jqueryvalidation.org/files/demo/ 在此处结帐演示http://jqueryvalidation.org/files/demo/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM