所以我只是尝试在3个文本字段不为空时启用按钮,如果它们变空则再次禁用该按钮。现在我只是尝试使用一个字段只是为了让它先工作但是不能让它工作,不知道为什么。要感谢任何帮助
<head>
<script type="text/javascript">
function checkEnableSubmit() {
if ( completePurchaseForm.address.value != "")
{document.getElementById("button").disabled = false;}
}
</script>
<form action="RegServlet" name="completePurchaseForm" method="post">
<table>
<tr>
<td> Address : </td><td> <input name="address" onkeyup="checkEnableSubmit()" id="address" size=100 type="text" /> </td>
</tr>
<tr>
<td> Card Type : </td><td> <input name="cardType" id="cardType" size=15 type="text" /> </td>
</tr>
<tr>
<td> Card Number : </td><td> <input name="cardNumber" id="cardNumber" size=15 type="text" /> </td>
</tr>
</table>
<input type="hidden" name="action" value="completePurchase" />
<input type="button" disabled name="submit" value="Complete your purchase" />
</form>
答案 0 :(得分:1)
将ID添加到按钮<input type="button" id="button1">
以使用document.getElementById("button1")
答案 1 :(得分:0)
试试这个:
<input name="address" onkeyup="checkEnableSubmit()" id="address" size=100 type="text" />
<input name="cardType" onkeyup="checkEnableSubmit()" id="cardType" size=15 type="text" />
<input name="cardNumber" onkeyup="checkEnableSubmit()" id="cardNumber" size=15 type="text" />
<input type="button" disabled name="submit" value="Complete your purchase" id="button" />
和此:
function checkEnableSubmit() {
var valid = true;
if ( completePurchaseForm.address.value != "")
valid = flase;
if ( completePurchaseForm.cardType.value != "")
valid = flase;
if ( completePurchaseForm.cardNumber.value != "")
valid = flase;
document.getElementById("button").disabled = valid;
}