I have to use a submit button to submit one of my forms on a website. Is it possible to use the <button> element as a submit button? Do I also add the type="submit" attribute to the <button> element? i.e.
<button type="submit">Go</button>
Yes, it's possible!
In fact, the <button>'s default behavior is to act as a submit button, so:
<button>Go</button>
Will do what you expect it to! Buttons are also slightly easier to style, and you can keep them consistent with other types of buttons without adding extra rules or selectors in your CSS.
It's worth noting that IE 7 and 6 have some pretty horrible bugs when using <button value="whatever">Something Else</button>. If you want lower IE compatibility and to use the value= attribute, don't use <button>
type=submit is the default type value. Also see the specssubmit: Creates a submit button. This is the default value. Emphasis mine. If you want, we can continue this discussion in chatFollowing are also 2 types to submit forms
<input type="submit">
The following script
<script>
function SubmitFunction()
{
document.getElementById("formid").submit();
}
</script>
<form id="formid" action="abc.php">
<input type="button" onclick="SubmitFunction()" value="Submit">
</form>
<button> element instead of an <input type="button"> element. I'd also recommend using <element>.addEventListener('click', ...); instead of directly setting an onclick attribute on the element.yes
You can use but I have heard that If you use the <button> element in an HTML form,
different browsers may submit different values. Use <input> to create buttons in an HTML form.