我的反饋表格出現問題。檢查一組電臺是否至少有一個選中
我只是想用jQuery或Javascript來驗證,每一組的單選按鈕始終一個按鈕來選擇,然後才能提交表單。
這是我的代碼從我的form.html。
<form id='form' method='POST' action='validate.php'>
<table>
<!-- Table header -->
<tr>
<th> </th>
<th>Always</th>
<th>Often</th>
<th>Rarely</th>
<th>Never</th>
</tr>
<!-- Group One -->
<tr>
<th>Dummy Text 1</th>
<th><input class='radio' type='radio' name='item[0]' value='always'></th>
<th><input class='radio' type='radio' name='item[0]' value='often'></th>
<th><input class='radio' type='radio' name='item[0]' value='rarely'></th>
<th><input class='radio' type='radio' name='item[0]' value='never'></th>
</tr>
<!-- Group two -->
<tr>
<th>Dummy Text 2</th>
<th><input class='radio' type='radio' name='item[1]' value='always'></th>
<th><input class='radio' type='radio' name='item[1]' value='often'></th>
<th><input class='radio' type='radio' name='item[1]' value='rarely'></th>
<th><input class='radio' type='radio' name='item[1]' value='never'></th>
</tr>
<!-- End of table -->
</table>
</form>
<button class='buttons' onclick='subForm()' name='submit'>Send Feedback</button>
<script>
function subForm() {
//Code
}
</script>
但我不知道我應該用來檢查是否檢查無線電按鈕。
我想document.getElementsByName
但這給我回不定值
由於提前
你有'getelementsbyclass'數組嗎?或者你得到了什麼輸出? – Lino
噢,你的意思是'getElementsByClassName',因爲你將無法正常工作:) – Lino
是的,我的意思是geElementsByClassName,我很懶惰,我通常依賴於我的開發環境/代碼編輯器自動完成這樣的事情對我來說。 –