我試圖檢查用戶是否至少選擇了一個單選按鈕。當點擊名爲mallname的複選框時,我需要檢查是否有一個付款收件箱已被檢查。Javascript檢查是否選擇了一個單選按鈕
這裏是我的支付HTML(我需要檢查,如果這兩個中的一個被選中)
<fieldset>
<legend>Payment method</legend>
<div class='container'>
<label for='payment' >Please select payment method.:</label>
<p>
<label for='payment' >Once off (Full Payment):</label>
<input type='radio' name='payment' id='paymentoo' onClick="SetHTML2('once')" value="Once off (Full Payment)" required <?php echo($isOnceoffFullPayment?'checked="checked"':''); ?> maxlength="50" />
<span id='register_payment_errorloc' class='error'></span>
<label for='payment' >Monthly Debit:</label>
<input type='radio' name='payment' id='paymentmd' onClick="SetHTML2('montly')" value="Monthly Debit" required <?php echo($isMonthlyDebit?'checked="checked"':''); ?> maxlength="50" />
<span id='register_payment_errorloc' class='error'></span>
<br>
</div>
</fieldset>
HTML的複選框
<td width='400'><label for='contract' >$malls</label></td><td width='100'><input type='checkbox' name='mallname[]' id='mallname' value='$malls' onclick = 'checkpayment(); addemupfull(); addemupfulldebit();'/></td>
這裏是我的Java
<script type="text/javascript">
function checkpayment(){
var payoo = document.getElementById("paymentoo");
var paymd = document.getElementById("paymentmd");
if(!(payoo || paymd).checked){
var malchecks = document.getElementById("mallname");
malchecks.checked = false;
alert("Please select a payment method first");
}
}
</script>
選擇'paymentoo'時有效,但選擇'paymentmd'時我仍然收到提示「請選擇付款方式OD第一」
感謝。很好的工作 –