求教一段js代码

来源:百度知道 编辑:UC知道 时间:2024/07/04 09:00:43
在做一段简单的可计算表单.
一开始价格定义为0, 然后每点选一个复选框就加上复选框value的价格.
最后点caculate得出总价.

参考了点资料,自己写的代码不工作,请教我.
=====
<body>
<form name="form1" >
<p align="center">
Please choose from the following options:<br>
<input type="checkbox" name="c1" value="1"> a <br>
<input type="checkbox" name="c2" value="2"> b <br>
<input type="checkbox" name="c3" value="3"> c <br>
<input type="checkbox" name="c4" value="4"> d <br>
</p>

<p align="center">
<input type="submit" name="caculate" value="caculate" onclick="caculate()">
<input type="text" name="t1" size="12" maxlength="20">
</p>
</form>

代码中有2处,一是obj=document.dhform,你的form名称 是form1,所以应该是obj=document.form1;

另外一个是 <input type="submit" name="caculate" value="caculate" onclick="caculate()">

这个input的名字叫做 caculate ,你的函数也是caculate ,这样 2个 就冲突了。 把 这个 input 的 name="caculate" 去掉就OK了

<body>
<form name="form1" >
<p align="center">
Please choose from the following options:<br>
<input type="checkbox" name="c1" value="1"> a <br>
<input type="checkbox" name="c2" value="2"> b <br>
<input type="checkbox" name="c3" value="3"> c <br>
<input type="checkbox" name="c4" value="4"> d <br>
</p>

<p align="center">
<input type="button" value="