DreamU
DreamU

Reputation: 1

HTML javascript form submitted when image input button

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

Answers (3)

Justin Gregoire
Justin Gregoire

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

Ray
Ray

Reputation: 21905

add 'return false;' to your onClick event:

onclick="printpage();return false;"

Upvotes: 3

Aric TenEyck
Aric TenEyck

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

Related Questions