好吧,我知道有一种简单的方法可以做到这一点,但是自从我做了很多javascript以来已经好几年了
我的客户有一个用于事件注册的在线订单表单(由之前的Web开发人员开发)。目前,订单总数只是一个隐藏的字段:
<INPUT value=78.00 type=hidden name=amount />
但我需要根据他们选择的日期计算总数:
<SELECT style="BACKGROUND-COLOR: #ffff99" name=altDate1>
<OPTION value=04/09> Friday, April 9 </OPTION>
<OPTION value=04/14> Wednesday, April 14 </OPTION>
<OPTION value=04/16> Friday, April 16 </OPTION>
<OPTION value=04/19> Monday, April 19 </OPTION>
<OPTION value=04/29> Thursday, April 29 </OPTION>
</SELECT>
这是处理表单的javascript:
<SCRIPT language=Javascript>
function PaymentButtonClick() {
document.addform.Product_Name.value = document.Information.StudentLastName.value + ","+
document.Information.StudentFirstName.value+","+
document.Information.StudentID.value+","+
document.Information.altDate1.name+","+","+
document.Information.Guests.value+ "," +
document.Information.StudentType.value;
document.addform.Product_Code.value = document.Information.StudentID.value;
if ((document.Information.UCheck.checked==true) &&
(document.Information.altDate1.value != "") &&
(document.Information.altDate1.value != "x")) {
if (document.Information.StudentLastName.value != "" ||
document.Information.StudentFirstName.value != "" ||
document.Information.StudentID.value != "" ) {
document.addform.submit();
}
else {
alert("Please enter missing information");
}
}
}
</SCRIPT>
答案 0 :(得分:0)
将此switch
语句插入表单处理函数:
switch (document.Information.altDate1.value) {
case '04/09':
document.Information.amount.value = 78.00;
break;
case '04/14':
document.Information.amount.value = 79.00;
break;
case '04/16':
document.Information.amount.value = 80.00;
break;
case '04/19':
document.Information.amount.value = 81.00;
break;
case '04/29':
document.Information.amount.value = 82.00;
break;
}