0

所以我只是试图在 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>
4

2 回答 2

1

将 id 添加到您的按钮<input type="button" id="button1">以使用document.getElementById("button1")

于 2013-05-03T00:38:13.897 回答
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;
  }
于 2013-05-03T00:41:42.860 回答