Reputation: 1
I have a form that contains this single input field, which is nothing more than a button to Print the current web page:
<div align="center">
<input type="image" src="../Images/print.jpg" value="Print" onclick="printpage();" /></div>
</div>
After the printing, the page re-submits itself (to itself). Why does it do this and can I stop it?
If I just change the type to "input", this code does not re-submit itself after printing:
<div align="center">
<input type="input" src="../Images/print.jpg" value="Print" onclick="printpage();" /></div>
</div>
Unfortunately, our style conventions require me to use that button image rather than the standard input button.
Upvotes: 0
Views: 2174
Reputation: 2583
Have you tried adding a
return false;
at the end of your code therefor
<input type="input" src="../Images/print.jpg" value="Print" onclick="printpage();return false;" /></div>
Upvotes: 0
Reputation: 21905
add 'return false;' to your onClick event:
onclick="printpage();return false;"
Upvotes: 3
Reputation: 8032
Change the onclick
handler to onclick="printpage(); return false;"
- that will prevent the button from doing anything besides running the JavaScript.
Upvotes: 5