1 javascript checkbox events if-statement onclick
我是javascript的新手,但我正在尝试制作一个复选框,将billto信息复制到shipto框中.我有一个onclick事件的复选框,设置如下:
<input type="checkbox" name="chkSame" id="chkSame" onClick="fncCheckbox()"/> same as customer info<br/>
Run Code Online (Sandbox Code Playgroud)
但是,我在以下函数的Else行中得到了"Expected';'"的错误.如果我完全取出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>
Run Code Online (Sandbox Code Playgroud)