TIMEX
TIMEX

Reputation: 272014

How do I have an input button and <a> tag?

I have this:

<a>
Stuff stuff stuff
<input type="Submit" onclick="....">
</a>

The problem is...when I click the submit button, it goes to the instead of onclick.

Upvotes: 0

Views: 75

Answers (3)

AxelEckenberger
AxelEckenberger

Reputation: 16926

Returning false from you on click handler should prevent the default behaviour, e.g.:

<a href="index.html">
  Stuff stuff stuff
  <input type="Submit" onclick="alert('test'); return false;">
</a>

Upvotes: 1

Jeff Maes
Jeff Maes

Reputation: 705

you can also make an <a> look like a button using CSS display: block or display: inline-block

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382796

Try this:

<input type="Button" onclick="....">

Use Button type instead of Submit :)

If you still want to use Submit, just place return false after your code eg:

<input type="Submit" onclick="doStuff(); return false;">

Upvotes: 2

Related Questions