Reputation: 11543
at the end of my web <form>
there are two buttons - one is <input type="submit">
and another is just <button>
. the problem is that if I click <button>
, it submits all the form. I wanted to assign some javascript function to that button instead of submitting, but since it auto-submits I can't do anything. How can I fix this?
Upvotes: 0
Views: 911
Reputation: 639
The onclick
must return false
to denote it will not Submit
, true
will denote , it will Submit
the form.
<button name="button1" onclick="button1_clicked();return false;">Click Me</button>
Upvotes: 0
Reputation: 724
Make the type as button and you can add onclick event to call javascript function.
<button type="button" onclick='alert(1);'></button>
Upvotes: 0
Reputation: 1577
Explain button type as button
because by default it is submit
<button type=button>Submit</button>
Upvotes: 6