1

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>
0

3 Answers 3

5

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>

Sign up to request clarification or add additional context in comments.

11 Comments

If you use <button> as a submit you need to add type=submit as well. Otherwise, it is a type=button by default.
Have you tried put <button> inside a form element? If not go and have a try so you'll learn a lot.
According to the specs, submit: Creates a submit button. This is the default value. Emphasis mine. If you want, we can continue this discussion in chat
"If not go and have a try so you'll learn a lot.". For an experienced user this sounds exactly as "I don't know what I'm speaking about"
|
0

Following are also 2 types to submit forms

  1. <input type="submit">

  2. 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>
    

1 Comment

While this solution may still work, I would use a <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.
-1

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.

5 Comments

You've heard? Heard where?
OK, so some information from MDN: "IE7 has a bug where when submitting a form with <button... value="foo">Click me</button>, the POST data sent will result in myButton=Click me instead of myButton=foo. IE6 has an even worse bug where submitting a form through a button will submit ALL buttons of the form, with the same bug as IE7. This bug has been fixed in IE8". So, to be specific - if you want IE7 compatibility, and want the button to pass a value, don't use it.
FYI - you should "check it", as it's your answer!
w3schools.com/tags/tag_button.asp Read this link, Hope this satisfies u
Firefox does not submit the button's value at all. Same exact page works fine in Chrome and submits the buttons value when clicked. Standards my ass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.