日期:2014-05-20  浏览次数:20649 次

如何用javascript 做一个表单提交
如何用javascript   做一个表单提交
<html>
<head>
<script   language=javascript>
function   a()
{
var   n=document.getElementById( 'n ').value;
var   m=document.getElementById( 'm ').value;
var   c=parseInt(a)+parseInt(b);


}
</script>
</head>

<body>
<form   name>
<input   type= "text "   id= "n "/>   +
<input   type= "text "   id= "m "/>   =
<input   type= "text "   id= "c "/>

<input   onload=javascript:a();   type= "button "     value= "加法 "/>
</body>
</html>

------解决方案--------------------
formname.submit();
------解决方案--------------------
document.forms[0].submit();
------解决方案--------------------
你提交也得不到值,需要使用
<input name= "x "

需要写name属性
------解决方案--------------------
document.formname.submit();
------解决方案--------------------
<input onload=javascript:a(); type= "button " value= "加法 "/> 为什么用onload()方法?onclick调用那个函数就可以了。
<html>
<head>
<script language=javascript>
function a()
{
var n=document.getElementById( 'n ').value;
var m=document.getElementById( 'm ').value;
var c=parseInt(m)+parseInt(n);

document.myform.sum.value=c;
}
</script>
</head>

<body>
<form name= "myform ">
<input type= "text " id= "n "/> +
<input type= "text " id= "m "/> =
<input type= "text " id= "sum "/>

<input onclick= "a(); " type= "button " value= "加法 "/>
</body>
</html>

还有你没有做输入校验。是否只能输入数字?