Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button Onclick does not work inside form

Good Day

I am using an ASP.NET webform where I have wrapped the following button inside the form tags:

<form runat="server">

  <button class="btn btn-primary" onclick="window.location='http://google.co.za';">Login</button>

</form>

ISSUE: The problem is that when clicking on the button, it just directs to the current page...does not redirect. However, when I remove the form tags, the button works. If I leave the form tags and I use an anchor tag to relocate, it works as well...It is just the button that is giving me issues.

Why is that?

I am using Twitter bootstrap as well(extra info..)

Thank you

like image 723
DextrousDave Avatar asked Sep 27 '26 01:09

DextrousDave


1 Answers

Add type="button" attribute to your button tag. Without it button works as submit.

like image 117
Igor Avatar answered Sep 28 '26 22:09

Igor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!