has the HTML version changed lately (like from ie7 to IE8?) I notice the following change that cause me some troulbe - I am having a code that is similar to this:
<form method="POST" action="/admin/modify"> <input type="text"/> <button onclick="dosomething()">Press</button> </form> <script type="text/javascript"> function doSomething(){ // doesn't matter what actually } </script>
What is weired to me in this code is that by pressing the button inside the form, all I want is to perform some javascript action but eventaully it causes the form to be submitted too, even when I am not willing to do it.
So - is it true? and if so how can I perform some java script actoin inside a from but prevent the form from being submitted automatically?
By default, a button has an innate type property of submit . When tapped, clicked, or activated inside a form, it will cause that form to submit (and trigger a corresponding submit event). let form = document.
submit : The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form> , or if the attribute is an empty or invalid value.
You can check if the user clicked the back button, disable form if true. Another way is by storing a cookie which you check on page load, if it exists you can disable the form.
According to W3schools, submit
is the new default action for button
elements in IE 8:
Always specify the type attribute for the button. The default type for Internet Explorer is "button", while in other browsers (and in the W3C specification) it is "submit".
So if you don't specify a type, the form will be submitted in all browsers, but not IE 7.
this should work:
<button type="button" onclick="dosomething()">Press</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With