使用javascript在struts1中提交表单
我正在尝试使用 javascript 提交。由于我无法找到使用“document.forms”,所以我使用了“document.getElementById”,但现在我无法为其分配操作类。有人可以帮助我吗?
我的代码:
<html>
<head>
just to check javascript form submission
</head>
<body>
<script>
function formsubmission(value){
alert("i am here just before the form submission"+value);
document.forms["ashutosh"].submit();
alert("i am just after the form submission");
}
</script>
<form id="ashutosh" action="http://www.gmail.com">
<select onchange="javascript:formsubmission(this.formName)">
<option value="1">ashutosh</option>
<option value="2">ashutosh1</option>
<option value="3">ashutosh2</option>
</select>
</form>
</body>
</html>
错误:
Object #<HTMLElement> has no method 'submit'
I am trying to submit using javascript . Since I was not able to find using "document.forms" so i used "document.getElementById" but now i am not able to assign action class to it .Can someone help me on this .
My code :
<html>
<head>
just to check javascript form submission
</head>
<body>
<script>
function formsubmission(value){
alert("i am here just before the form submission"+value);
document.forms["ashutosh"].submit();
alert("i am just after the form submission");
}
</script>
<form id="ashutosh" action="http://www.gmail.com">
<select onchange="javascript:formsubmission(this.formName)">
<option value="1">ashutosh</option>
<option value="2">ashutosh1</option>
<option value="3">ashutosh2</option>
</select>
</form>
</body>
</html>
Error :
Object #<HTMLElement> has no method 'submit'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更简单:
演示:http://jsfiddle.net/mattball/N4fxn/
Much simpler:
Demo: http://jsfiddle.net/mattball/N4fxn/
第一个错误, this 不存在:
“this”指的是选择标签而不是表单,this.form 指的是表单。
看起来您正在尝试获取表单的名称,
您可以通过表单的对象 .name 属性来获取该名称,但仅当您定义了 name 属性时
first error , this does not exist :
"this" refers to select tag rather than the form, this.form refers to the form.
It seems like you are trying to get the form's name,
you get that by form's object .name property, but only when you have name attribute defined