大学生社交心理:ASP中输入框自动计算问题

来源:百度文库 编辑:中科新闻网 时间:2024/05/09 08:20:11
两个输入框,一个输入金额一个输入百分比,数据库中有一个总金额,想要实现在一个输入框中输入数据,另一个输入框可以自动计算出相应的百分比或金额。
我想用input onchange 然后执行javascript,具体怎么实现?

<!--变量总金额-->
<%counts=总金额%>
<script language="vbscript">
<!--
sub checkmoney()
if form.moneys.value<>"" then
form.moneybf.value=form.moneys.value/counts*100&"%"
else
form.moneybf.value=0
end if
end sub

sub checkmoneybf()
if form.moneybf.value<>"" then
form.money.value=counts*form.moneybf.value
else
form.money.value=0
end if
end sub
-->
</script>

<form name=form action="?add=yes" method="post">
<!--金额-->
<input type=text name=moneys value="" size=10 onchange="call checkmoney()" language="VBScript">
<!--百分比-->
<input type=text name=moneybf value="" size=10 onchange="call checkmoneybf()" language="VBScript">
<input class=editbox type="button" name="Button" value="提 交">
</form>

<form name="mainForm">
<input type="text" name="precent" />
<input type="hidden" name="total" />
<input type="text" name="cost" onchange="fun()" />
<script language="javascript">
function fun(){
mainForm.precent.value = mainForm.cost.value \ mainForm.total.value & "%"
}
</script>
</form>