2013-05-03 74 views
0

所以即時通訊只是試圖啓用一個按鈕,當3個文本字段不爲空,並再次禁用按鈕,如果他們成爲empty.Right現在我只是試圖與一個現場只是爲了得到它的工作第一,但不能讓它的工作,也不知道why.Would感謝所有幫助試圖啓用一個禁用的按鈕,當一個文本框不爲空

 <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> 

回答

1

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

+0

這就是它感謝夥計:) – user2323975 2013-05-03 00:45:12

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; 
    } 
相關問題