admin管理员组文章数量:1332339
I need a theoretic clarification...What's the difference between JavaScript form submit and a form containing a submit button?
(I'm using the framework Struts, but I think it doesn't affect the behaviour.)
I mean, this is my example, what's the difference between submit a form with a input type="submit"
?
<html:form action="search.do?method=mySearch" method="post" styleId="searchFilterForm">
<input type="hidden" name="myfield" value="">
<table border="0" class="filterclass" width="530px">
<tr>
<td class="filterheader" align="center">
<input type="submit" onclick="doMySubmit()" name="MyList" value="SEND" class="button actionbutton" />
</td>
</tr>
</table>
</html:form>
function doMySubmit() {
var myform = document.getElementById('searchFilterForm');
myform.myfield.value = "Hello World";
}
And submitting the form with a submit inside JavaScript?
<html:form action="search.do?method=mySearch" method="post" styleId="searchFilterForm">
<table border="0" class="filterclass" width="530px">
<tr>
<td class="filterheader" align="center">
<input type="button" onclick="doMySubmit()" name="MyList" value="SEND" class="button actionbutton" />
</td>
</tr>
</table>
</html:form>
function doMySubmit() {
var myform = document.getElementById('searchFilterForm');
myform.myfield.value = "Hello World";
myform.submit();
}
I need a theoretic clarification...What's the difference between JavaScript form submit and a form containing a submit button?
(I'm using the framework Struts, but I think it doesn't affect the behaviour.)
I mean, this is my example, what's the difference between submit a form with a input type="submit"
?
<html:form action="search.do?method=mySearch" method="post" styleId="searchFilterForm">
<input type="hidden" name="myfield" value="">
<table border="0" class="filterclass" width="530px">
<tr>
<td class="filterheader" align="center">
<input type="submit" onclick="doMySubmit()" name="MyList" value="SEND" class="button actionbutton" />
</td>
</tr>
</table>
</html:form>
function doMySubmit() {
var myform = document.getElementById('searchFilterForm');
myform.myfield.value = "Hello World";
}
And submitting the form with a submit inside JavaScript?
<html:form action="search.do?method=mySearch" method="post" styleId="searchFilterForm">
<table border="0" class="filterclass" width="530px">
<tr>
<td class="filterheader" align="center">
<input type="button" onclick="doMySubmit()" name="MyList" value="SEND" class="button actionbutton" />
</td>
</tr>
</table>
</html:form>
function doMySubmit() {
var myform = document.getElementById('searchFilterForm');
myform.myfield.value = "Hello World";
myform.submit();
}
Share
Improve this question
edited Jul 14, 2019 at 21:28
Peter Mortensen
31.6k22 gold badges110 silver badges133 bronze badges
asked Sep 11, 2013 at 10:13
CiscoCisco
5321 gold badge8 silver badges25 bronze badges
2 Answers
Reset to default 9The most notable difference is that when submitting a form by clicking a submit button there'll be a request parameter corresponding to the button that was clicked. So, in your example, with the submit button there'd be a request parameter with a name of MyList
and a value of SEND
. If you call form.submit()
in JavaScript there won't be.
So if you called request.getParameter("MyList");
on your server-side, with the first method that will return a String with the value SEND and with the second it will return null
. This bees important when you want to control the flow through your Action based on whether or not the form has been submitted, or even which button was used to submit the form (if you had several).
If your user disable javascript, he can't submit the form. It's a better practice to add a type submit for accessibility. More information on this question
本文标签: htmlDifference between JavaScript form submit and a form containing a submit buttonStack Overflow
版权声明:本文标题:html - Difference between JavaScript form submit and a form containing a submit button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742329741a2454449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论