使用javascript在struts1中提交表单

发布于 2024-12-10 08:21:49 字数 875 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白芷 2024-12-17 08:21:49

更简单:

<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/

Much simpler:

<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>

Demo: http://jsfiddle.net/mattball/N4fxn/

万劫不复 2024-12-17 08:21:49

第一个错误, this 不存在:

this.formName

“this”指的是选择标签而不是表单,this.form 指的是表单。

看起来您正在尝试获取表单的名称,

您可以通过表单的对象 .name 属性来获取该名称,但仅当您定义了 name 属性时

<form id="something" name="something"> 

first error , this does not exist :

this.formName

"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

<form id="something" name="something"> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文