下面是我的代码,它序列化了单选按钮列表,这些单选按钮是由PHP生成的,然后使用javascript在客户端打印。
我需要的是, 在我选择所有单选按钮后,当我点击“提交”按钮时,我希望它能够" 检查是否所有单选按钮都是以"形式选中的,如果是单个/多个单选按钮未在表单中选择,那么我需要在每个未选择单选按钮旁边的 RED颜色星(强制符号)
然后传递给另一个将保存到DB的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:
$(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';
});
});
});