<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

</head>
<body>
<script type="text/javascript" language="Javascript"> 
function sum(){
sm.value=parseInt(num.value)+parseInt(pr.value);
}

    </script>
数 量:
<input type="text" name="数量" id="pr" onpropertychange="sum();">
计量单位:
<select name="计量单位">
<option value="个">

<option value="台">

<option value="辆">

</select>
单 价:
<input type="text" name="单价" id="num" onpropertychange="sum();">
总 价:
<input type="text" name="总价" id="sm">
<br>
<br>
</body>
</html>小弟是做一个在页面自动计算的东西!
这样是可以的!
可是加上了form就不可以!
请高手请教阿!

解决方案 »

  1.   

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">

    </head>
    <body>
    <script type="text/javascript" language="Javascript"> 


    function sum(){
    sm.value=parseInt(num.value)+parseInt(pr.value);
    }

        </script>

    <form action="">
    数 量:
    <input type="text" name="数量" id="pr" onpropertychange="sum();">
    计量单位:
    <select name="计量单位">
    <option value="个">

    <option value="台">

    <option value="辆">

    </select>
    单 价:
    <input type="text" name="单价" id="num" onpropertychange="sum();">
    总 价:
    <input type="text" name="总价" id="sm">
    <br>
    <br>
    </form>
    </body>
    </html>加上form,js就没用了!不知道为什么!请高手看看!
      

  2.   

    document.getElementById("sm").value=parseInt(document.getElementById("num").value)+parseInt(document.getElementById("pr").value);
      

  3.   


    给form 加上一个名字<form name="form1" action="">function sum(){
    form1.sm.value=parseInt(form1.num.value)+parseInt(form1.pr.value);
    }
      

  4.   

    action="" 既然是空的话你加上去干什么呢 
    别让他为空
      

  5.   

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <base href="<%=basePath%>">
            
        </head>
        <body>
        <script type="text/javascript" language="Javascript"> 
        
        
    function sum(){
    var num=document.form1.num.value;
    var pr = document.form1.pr.value;
    var sm= document.form1.sm.value;
    sm=parseInt(num)+parseInt(pr);
    }
        
        </script>
        
    <form action="" name="form1">
            数 量:
            <input type="text" name="pr" id="pr" onpropertychange="sum();">
            计量单位:
            <select name="计量单位">
                <option value="个">
                    个
                <option value="台">
                    台
                <option value="辆">
                    辆
            </select>
            单 价:
            <input type="text" name="num" id="num" onpropertychange="sum();">
            总 价:
            <input type="text" name="sm" id="sm">
            <br>
            <br>
            </form>
        </body>
    </html>
    大概的看了一下,写了一下,试试看行不行?
      

  6.   

    或者是
    var num= document.getElementById("num").value
    var pr= document.getElementById("pr").value
    var sm= document.getElementById("sm").value
      

  7.   

    现在问题的关键就是在from上面
    不加就可以!加了就不行!
      

  8.   

        <script type="text/javascript" language="Javascript">  
         
         
    function sum(){ 
    var num=document.all.num.value; 
    var pr = document.all.pr.value; document.all.sm.value=parseInt(num)*parseInt(pr); 

         
         </script> 
     把这个搞到head里进去 写到body里进去干嘛
      

  9.   

    好了!要加上document.getElementById
    就可以了!谢谢大家的帮助!