2 回答

TA貢獻1820條經驗 獲得超9個贊
這是正確的代碼之一。
<label>Subject : </label> <label><input type = "checkbox" name = "subject[]" id = "subject" <?php echo (in_array("Maths",$_POST["subject"]))?"checked" : " "?> value = "Maths"/>Maths</label> <label><input type = "checkbox" name = "subject[]" id = "subject" <?php echo (in_array("Maths",$_POST["subject"]))?"checked" : " "?> value = "English"/>English</label> <label><input type = "checkbox" name = "subject[]" id = "subject" <?php echo (in_array("Maths",$_POST["subject"]))?"checked" : " "?> value = "Tamil"/>Tamil</label>

TA貢獻1784條經驗 獲得超8個贊
如果您想將所有復選框稱為同名,則它們需要是一個數組
<label>
<input type="checkbox" name="subject[]" id="subject[]" <?php if (isset($_POST["subject"][0]) && $_POST["subject"][0]=="Maths") echo "checked";?> value = "Maths"/>Maths
</label>
<label>
<input type="checkbox" name="subject[]" id="subject[]" <?php if (isset($_POST["subject"][1]) && $_POST["subject"][1]=="English") echo "checked";?> value = "English"/>English
</label>
<label>
<input type="checkbox" name="subject[]" id="subject[]" <?php if (isset($_POST["subject"][2]) && $_POST["subject"][2]=="Tamil") echo "checked";?> value = "Tamil"/>Tamil
</label>
- 2 回答
- 0 關注
- 135 瀏覽
添加回答
舉報