在我的Html表單中,有幾個複選框字段用戶可以選擇或不選擇。現在,如果用戶選擇所有複選框,然後窗體顯示成功消息,但如果沒有選中所有複選框,則顯示幾條錯誤消息。所以它沒有顯示成功消息。錯誤消息是這個樣子的:如果所有複選框未被選中,則顯示錯誤消息(多個複選框)
Notice: Undefined variable: mon_morning in D:\software installed\xampp installed\htdocs\tutor
\tutor_request.php on line 142
Notice: Undefined variable: mon_afternoon in D:\software installed\xampp installed\htdocs\tutor
\tutor_request.php on line 142
more.....
我的HTML複選框形式:
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="mon_morning" value="mon_morning" id="checkAll"/> <strong>MON</strong></td>
<td><input type="checkbox" name="mon_morning" value="mon_morning" class="checkItem"/> Morning</td>
<td><input type="checkbox" name="mon_afternoon" value="mon_morning" class="checkItem"/> Afternoon</td>
<td><input type="checkbox" name="mon_evening" value="mon_evening" class="checkItem"/> Evening</td>
</tr>
<tr>
<td><input type="checkbox" name="tue_morning" value="tue_morning" id="checkAll_1"/> <strong>TUE</strong></td>
<td><input type="checkbox" name="tue_morning" value="tue_morning" class="checkItem_1"/> Morning</td>
<td><input type="checkbox" name="tue_afternoon" value="tue_morning" class="checkItem_1"/> Afternoon</td>
<td><input type="checkbox" name="tue_evening" value="tue_evening" class="checkItem_1"/> Evening</td>
</tr>
<tr>
<td><input type="checkbox" name="wed_morning" value="wed_morning" id="checkAll_2"/> <strong>WED</strong></td>
<td><input type="checkbox" name="wed_morning" value="wed_morning"/> Morning</td>
<td><input type="checkbox" name="wed_afternoon" value="wed_morning"/> Afternoon</td>
<td><input type="checkbox" name="wed_evening" value="wed_evening"/> Evening</td>
</tr>
<tr>
<td><input type="checkbox" name="thu_morning" value="thu_morning" id="checkAll_3"/> <strong>THU</strong></td>
<td><input type="checkbox" name="thu_morning" value="thu_morning"/> Morning</td>
<td><input type="checkbox" name="thu_afternoon" value="thu_morning"/> Afternoon</td>
<td><input type="checkbox" name="thu_evening" value="thu_evening"/> Evening</td>
</tr>
<tr>
<td><input type="checkbox" name="fri_morning" value="fri_morning" id="checkAll_4"/> <strong>FRI</strong></td>
<td><input type="checkbox" name="fri_morning" value="fri_morning"/> Morning</td>
<td><input type="checkbox" name="fri_afternoon" value="fri_morning"/> Afternoon</td>
<td><input type="checkbox" name="fri_evening" value="fri_evening"/> Evening</td>
</tr>
<tr>
<td><input type="checkbox" name="sat_morning" value="sat_morning" id="checkAll_5"/> <strong>SAT</strong></td>
<td><input type="checkbox" name="sat_morning" value="sat_morning"/> Morning</td>
<td><input type="checkbox" name="sat_afternoon" value="sat_morning"/> Afternoon</td>
<td><input type="checkbox" name="sat_evening" value="sat_evening"/> Evening</td>
</tr>
<tr>
<td><input type="checkbox" name="sun_morning" value="sun_morning" id="checkAll_6"/> <strong>SUN</strong></td>
<td><input type="checkbox" name="sun_morning" value="sun_morning"/> Morning</td>
<td><input type="checkbox" name="sun_afternoon" value="sun_morning"/> Afternoon</td>
<td><input type="checkbox" name="sun_evening" value="sun_evening"/> Evening</td>
</tr>
</table>
PHP表單我如何處理複選框:
if(isset($_POST['mon_morning'])) { $mon_morning = inputvalid($_POST['mon_morning']);}
if(isset($_POST['mon_afternoon'])) $mon_afternoon = inputvalid($_POST['mon_afternoon']);
if(isset($_POST['mon_evening'])) $mon_evening = inputvalid($_POST['mon_evening']);
if(isset($_POST['tue_morning'])) $tue_morning = inputvalid($_POST['tue_morning']);
// more.....
的Javascript我使用檢查一行內的所有複選框
<script>
$('td:first-child input[type="checkbox"]').on('change', function(){
$(this)
.closest('td')
.siblings()
.find('input[type="checkbox"]').prop('checked', this.checked);
});
</script>
什麼是你形成方法GET/POST? –