admin管理员组文章数量:1316399
i have a form with an element of type button. I want to use the onclick method to set an image of an img tag, and then simulate the "action" of the form. I tried the following code:
<html>
<head>
<script type="text/javascript">
function imgtest(){
document.getElementById
("test").src="progress.gif";
}
</script>
<title>Hello</title>
<body>
<form method="POST" action="test.php">
<input type="button" value="Submit"
onclick="imgtest()">
</form>
<div id="img">
<img id="test" src="load.png">
</div>
</body>
</html>
Though, this does not seem to work. What may be the other solution?
i have a form with an element of type button. I want to use the onclick method to set an image of an img tag, and then simulate the "action" of the form. I tried the following code:
<html>
<head>
<script type="text/javascript">
function imgtest(){
document.getElementById
("test").src="progress.gif";
}
</script>
<title>Hello</title>
<body>
<form method="POST" action="test.php">
<input type="button" value="Submit"
onclick="imgtest()">
</form>
<div id="img">
<img id="test" src="load.png">
</div>
</body>
</html>
Though, this does not seem to work. What may be the other solution?
Share Improve this question asked Sep 2, 2013 at 11:57 Gaurav SoodGaurav Sood 6904 gold badges17 silver badges39 bronze badges 1- 1 Why not change the image on the form's onSubmit event? – Rob Farr Commented Sep 2, 2013 at 12:00
5 Answers
Reset to default 4you can do it like this
give an id to your form
<form method="POST" action="test.php" id="someid">
on button click method in jquery
$('#buttonid').click(
function(){
$("#someid").submit();
});
use document.getElementById('formidhere').submit();
//for javascript solution
While type="submit"
controls do submit their form automatically, type="button"
s do not. You can trigger the submission with JavaScript by executing
this.form.submit();
at the end of the click event handler of the button (that is inside the form).
There is no need to use jQuery or to give an ID to the form, as form controls always refer back to their form.
In Javascript
document.getElementById('form').submit();
In JQuery
$('#button').click(function() {
$('#form').submit();
});
First give the id to your form
ex.
<form method="POST" action="test.php" id="testForm">
then in you button click event write as below in your imgtest() function :
document.getElementById('testForm').submit();
function imgtest(){
document.getElementById("test").src="progress.gif";
var frm=document.getElementById("frm1");
frm.submit();
}
本文标签: htmlsubmit of form using type button javascriptStack Overflow
版权声明:本文标题:html - submit of form using type button javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742002888a2411373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论