我正在尝试根据提供的值计算表单,我编写了脚本,但它说缺少;在陈述之前
这是我的代码,如果有人能看到错误,请帮助指出。
<script type="text/javascript">
function calc(theForm) {
var myEquip1 = document.Edit.EQup1.value;
var myEquip2 = document.Edit.EQup2.value;
Var myFixedPrice = document.Edit.InitialPrice.value;
Var myEquip1Price = document.Edit.EQup1Price.value;
Var myEquip2Price = document.Edit.EQup2Price.value;
if (myEquip1 > 1)
{
var myEquip1Total = (myEquip1*myEquip1Price) - (myEquip1Price);
}
else
{
var myEquip1Total = (myEquip1*myEquip1Price)-(myEquip1Price);
}
if (myEquip2 > 1)
{
var myEquip2Total = (myEquip2*myEquip2Price)-(myEquip2Price);
}
else
{
var myEquip2Total = (myEquip2*myEquip2Price)-(myEquip2Price);
}
theForm.GrandTotal.value = (myEquip2Total+myEquip1Total+myFixedPrice)
}
</script>
HTML在下面我确定我做错了但我能看到它。
<form name="Edit" method="post" action="mypageprocess">
<p><label for="EQup1">How many Branches?</label><br />
<select name="EQup1" onChange="calc(this.form)" id="EQup1"/>
<option value="0">Please select</option>
<option value="1" >One</option>
<option value="2" >Two</option>
<option value="3" >Three</option>
<option value="4" >Four</option>
<option value="5" >Five</option>
</select> x <strong>$550.00</strong>
</p>
<p><label for="EQup2">How many Satellits?</label><br />
<select name="EQup2" onChange="calc(this.form)" id="EQup2"/>
<option value="0">Please select</option>
<option value="1" >One</option>
<option value="2" >Two</option>
<option value="3" >Three</option>
<option value="4" >Four</option>
<option value="5" >Five</option>
</select> x <strong>$440.00 </strong>
</p>
<input type="text" onfocus="this.blur();" name="GrandTotal" size="10" readonly="readonly"/>
<input type="hidden" name="InitialPrice" value="660" />
<input type="hidden" name="EQup1Price" value="550" />
<input type="hidden" name="EQup2Price" value="440" />
</form>
谢谢
答案 0 :(得分:5)
JavaScript区分大小写。 Var
无效,请使用var
。
答案 1 :(得分:2)
您的<select>
个元素都过早关闭,就好像它们没有内部内容一样。