0

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.

1
  • 1
    If the image button has no functionality without Javascript, then write it with Javascript into the document. Commented Apr 1, 2010 at 15:54

3 Answers 3

5

Change the onclick handler to onclick="printpage(); return false;" - that will prevent the button from doing anything besides running the JavaScript.

Sign up to request clarification or add additional context in comments.

1 Comment

Might be worth mentioning that the reason you need to do this is that an input element of type "image" is by default a submit button, and therefore submits the form when clicked.
3

add 'return false;' to your onClick event:

onclick="printpage();return false;"

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.