2010-07-23 8 views
1

我對javascript很陌生,但我試圖創建一個複選框,將billto信息複製到shipto框中。我有一個onclick事件的複選框,設置像這樣:「其他」在JavaScript函數中不起作用

<input type="checkbox" name="chkSame" id="chkSame" onClick="fncCheckbox()"/> same as customer info<br/> 

我得到的錯誤「預期‘;’」在下面的函數在Else線,雖然。如果我完全取出IF語句,它就可以工作。如果我剛剛擺脫了ELSE,或者如果我將ELSE作爲1行並刪除{}括號,它會起作用。當我在測試頁面上設置非常相似的東西時,它可以工作。我不知道爲什麼它在這種情況下不起作用。功能如下:

<script type="text/javascript"> 
    function fncCheckbox() 
    { 
if (document.RepairRequestform.chkSame.checked) { 
      document.RepairRequestform.txtShipName.value = document.RepairRequestform.txtBillName.value; 
      document.RepairRequestform.txtShipCompany.value = document.RepairRequestform.txtBillCompany.value; 
    document.RepairRequestform.txtShipAddress.value = document.RepairRequestform.txtBillAddress.value; 
    document.RepairRequestform.txtShipAddress2.value = document.RepairRequestform.txtBillAddress2.value; 
    document.RepairRequestform.txtShipCity.value = document.RepairRequestform.txtBillCity.value; 
    document.RepairRequestform.txtShipState.value = document.RepairRequestform.txtBillState.value; 
    document.RepairRequestform.txtShipZip.value = document.RepairRequestform.txtBillZip.value; 
    } Else { 
    document.RepairRequestform.txtShipName.value = ""; 
    document.RepairRequestform.txtShipCompany.value = ""; 
    document.RepairRequestform.txtShipAddress.value = ""; 
    document.RepairRequestform.txtShipAddress2.value = ""; 
    document.RepairRequestform.txtShipCity.value = ""; 
    document.RepairRequestform.txtShipState.value = ""; 
    document.RepairRequestform.txtShipZip.value = ""; 
} 
    } 
</script> 

回答

11

否則應該是全部小寫,JavaScript區分大小寫。

+0

啊,我太慢了... + 1 – heisenberg 2010-07-23 22:04:41