Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  118] [ 4]  / answers: 1 / hits: 19343  / 11 Years ago, mon, september 2, 2013, 12:00:00

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?


More From » html

 Answers
7

While type=submit controls do submit their form automatically, type=buttons 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.


[#75960] Saturday, August 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;