I have ASP.Net code generating my button's HTML for me using divs to get it to look and behave how I want. This question is regarding the HTML produced by the ASP.Net code.
A standard button is easy, just set the onClick event of the div to change the page location:
<div name="mybutton" id="mybutton" class="customButton" onClick="javascript:document.location.href='wherever.html';">
Button Text
</div>
This works great, however, if I want a button like this to submit the form in which it resides, I would have imagined something like below:
<form action="whatever.html" method="post">
<div name="mysubmitbutton" id="mysubmitbutton" class="customButton" onClick="javascript:this.form.submit();">
Button Text
</div>
</form>
However, that does not work :( Does anyone have any sparkling ideas?
<button>
element instead. Likewise you shouldn't use javascript to submit a form if there is no fallback for browsers with scripting disabled. – Rosalbaborder
,background-color
anddisplay
properties. Likewise, any element inside the button can be styled to behave like a div (e.g. a span withdisplay: block
). That being said, these days accessibility hints can make a div be recognised as a button, so it doesn't really matter as long as you remember to make your site accessible. – Rosalba