javascript - 使用javascript在struts1中提交表单

标签 javascript struts

我正在尝试使用 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'

最佳答案

更简单:

<html>
    <head></head>
    <body>
        <form action="http://www.example.com">
            <select onchange="this.form.submit()">
                <option value="1">ashutosh</option>
                <option value="2">ashutosh1</option>
                <option value="3">ashutosh2</option>
            </select>
        </form>
    </body>
</html>

演示:http://jsfiddle.net/mattball/N4fxn/

关于javascript - 使用javascript在struts1中提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7801620/

相关文章:

javascript - react-slick 旋转木马通过滚动事件循环播放幻灯片 - react js, javascript

javascript - 如何在嵌入 swf 对象中禁用鼠标捕获?

javascript - 对话框打开后停止加载页面

java - 如何从html :options collections获取选定选项值

javascript - 如何编写可重用和模块化的 Redux 选择器?

javascript - highcharts custombutton hover and press 默认情况下更改颜色

spring - 简单的JSp和servlet代码可以迁移到Spring框架吗?

java - Struts2,使用 method={1} 的最佳实践

java - 我如何在单独的线程中执行大量 WS 调用并递增单个结果变量?

java - 错误: No tag "iterator" defined in tag library imported with prefix "logic"