2

If I do not specify name attribute within tag, is everything within form is submitted successfully?

I know that without name is not submitted in either GET or POST

2
  • 1
    Yes, all values of form controls with [name] are submitted with one exception: <output> . If you want to send the value of an <output> just copy it over to a <input type='hidden'>. Also, if you have a group of radio buttons that have the same [name] -- only the value of the selected radio button is submitted. Commented Mar 18, 2019 at 17:12
  • check by answer bro i will help u for sure . Commented Mar 19, 2019 at 5:38

4 Answers 4

1

Submitting a <form>

"Is form submitted if tag has no name attribute (and child elements within form do have name attribute?"

  • Yes, all values of form controls1 with a [name] and nested within a <form>2 tag are submitted with one exception: <output>. If you want to send the value of an <output> just copy it over to a <input type='hidden'>.
  • Forms do not require a [name] attribute to send values of its children tags or for itself (since forms actually don't have value attributes).
  • If you have a group of radio buttons that have the same [name] -- only the value of the selected radio button is submitted.
  • There is a default behavior the <button> tag has when nested within a form it will act as a <input type="submit">. So remember to add type="button" to <button>s that are just buttons to trigger a click event instead of a submit event.
  • If focus is set within a form and the enter (return for Macs) key is clicked also triggers a submit event.

1Children tags of a <form> tag that have the [name]/value sent during a submission is known as successful controls.
2If a form control is not a child of a form, an association can be enabled by assigning the control form="FORMID"


Demo

<form>

  • [action]: Sends to a live test server
  • [target]: [name] of an iframe that displays the server's response
  • [onchange]: Whenever the user leaves data on the form -- <output> displays the value of the selected radio button and <output> assigns the value to the hidden input as well.

#ui {
  width: 300px;
}

#out,
button,
[type=submit] {
  float: right;
}
<form id='main' action='https://httpbin.org/post' method='post' target='response' onchange='out.value = rad.value; inv.value = out.value; return false'>
  <fieldset id='ui'>
    <legend>Submitting a Form</legend>
    <fieldset>
      <input id='xA' name='rad' type='radio' value='A'> A
      <input id='xB' name='rad' type='radio' value='B'> B
      <input id='xC' name='rad' type='radio' value='C'> C
      <input id='xD' name='rad' type='radio' value='D'> D
      <output id='out' name='out' for='xA xB xC xD inv'></output>
      <input id='inv' name='inv' type='hidden'>
    </fieldset>
    <button>&lt;button&gt;</button>
    <input type='submit'>
  </fieldset>
</form>
<iframe name='response'></iframe>

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

Comments

1

yes form will submit even if it has not no name. check the code below it will explain you.

Click on the submit button form will submit, even if it does not have name,action etc. submit button is enough to submit the form.

If you dont mention meathod then default submit type is "Get" meathod

<form action='/cloud' meathod="get">
<input type ="submit" value="submit"/>
</form>

Comments

1

Yes!

FYI - use of name attributes on forms are deprecated for id in HTML5. See the MDN note about it.

The name of the form. In HTML 4, its use is deprecated (id should be used instead). It must be unique among the forms in a document and not just an empty string in HTML 5.

Edits:

  1. fixed typo from earlier post on mobile that made it seem like I was suggesting <input> name attributes are deprecated.
  2. Added quote from MDN

1 Comment

MDN is incorrect, or at least misleading. The name attribute on form elements is not deprecated or obsoleted in either HTML 4 or HTML 5. It's true that the HTML 4 spec encourages the use of id instead, but does not formally deprecate the attribute. HTML 5 does not even do that. HTML 4's definition of the name attribute on the form element. HTML 5's definition of the name attribute on the form element
0

yes you have give form method like:

<form method="post OR get">
</form>

and also give element name because element name used to post the value of that element.

Comments

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.