我有一个包含2个单选按钮的表单。并且,在表单的底部是"提交"按钮。
一键是选择Paypal作为付款方式;另一个按钮是选择信用卡。
我写了一个脚本来"禁用"提交,除非选择了其中一个单选按钮。
出于某种原因,我的"提交"按钮仍然已禁用。 ((
这是我的剧本:
<script
src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'>
</script>
<script type='text/javascript'>
function displayForm(c) {
if (c.value == "2") {
jQuery('#paypalformContainer').toggle('show');
jQuery('#ccformContainer').hide();
if(document.getElementById('radio2').checked==true)
{
document.getElementById('radio1').checked=false;
}
}
if (c.value == "1") {
if(document.getElementById('radio1').checked==true)
{
document.getElementById('radio2').checked=false;
}
jQuery('#ccformContainer').toggle('show');
jQuery('#paypalformContainer').hide();
}
};
</script>
<script type="text/javascript">
function fCheck() {
var x = document.getElementById('radio1').value;
var x2 = document.getElementById('radio2').value;
if (x==null || x=="") {
document.getElementById('submit').disabled=true;
} else { if (x2==null || x2=="") {
document.getElementById('submit').disabled=true; } else {
document.getElementById('submit').disabled=false; } } }
</script>
这是形式本身:
<form name="topup" id="topup" method="post" action="top_up">
<input value="1" type="radio" name="formselector" id="radio1"
onClick="displayForm(this),fCheck()"></input>Via Credit Card<br><br>
<input value="2" type="radio" name="formselector" id="radio2"
onClick="displayForm(this),fCheck()"></input>Via Paypal
<div style="display:none" id="ccformContainer">
<br>
<form id="ccform">
<label>Enter your credit card details : </label>
<br>
<br>
<dd>
<p>Credit Card Name :
<input type="text" id="ccname" name="ccname" value="$ccname">
</p>
<p>Credit Card Type :
<select name="cctype" required>
<option value="Visa">Visa</option>
<option value="Mastercard">Mastercard</option>
<option value="American Express">American Express</option>
<option value="Discover">Discover</option>
<option value="Diners Club">Diners Club</option>
<option value="Maestro">Maestro</option>
<option value="Verified By Visa">Verified By Visa</option>
<option value="Visa Electron">Visa Electron</option>
</select>
<p>Credit Card Number :
<input type="text" minlength="16" id="ccnumber"
name="ccnumber" value="$ccnumber">
</p>
<p>Credit Expiry Date : Month :
<select name="ccexpdatemonth" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select> <span>Year : <select name="ccexpdateyear"
required>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
</select></span>
<p>Credit Card CVC :
<input type="text" minlength="3" id="cccvc" name="cccvc"
value="$cccvc">
</p>
</dd>
</form>
</div>
<br>
<br>
<br>
<div style="display:none" id="paypalformContainer">
<form id="paypalform">
<label>Enter your Paypal Details :</label>
<dd>Paypal Address :
<input type="text" id="paypal" name="paypal"
value="$paypal">
</dd>
</form>
</div>
<br>
<div style="text-align:center"><input type="submit"
name="submit" id="submit" value="Pay Here" disabled></div>
</form>