简体   繁体   中英

“else” doesn't work in javascript function

I'm very new to javascript but I'm trying to make a checkbox that will copy the billto information into the shipto boxes. I have the checkbox with an onclick event, set up like so:

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

I get an error of "Expected ';'" on the Else line in the following function, though. It works if I take out the IF statement altogether. It works if I just get rid of the ELSE or if I leave the ELSE as 1 line and get rid of the { } brackets. It works when I set up something very similar on a test page. I have no idea why it doesn't work in this case though. The function is below:

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

否则应该全部小写,JavaScript区分大小写。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM