Reputation: 139
HTML 1:
<html>
<body>
<form>
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
HTML 2:
<html>
<body>
<form>
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
<input type="email" value="email">
</body>
</html>
I know that <form>
element is used to collect the user input and pass it to the specific url. In the HTML 1 when the submit button is selected the data inside the <form>
element is collected and passed to the url mentioned.
I have same code in the HTML 2 but I have included another <input>
element outside the <form>
element.
So, my doubt is that when the submit button is selected in the HTML 2 what will happen to the <input>
element outside the <form>
, will the value entered be read or not? If yes or no what is the reason, because if my understanding is correct submit
is inside the <form>
element so it will read the values inside the <form>
and ignore the <input>
element placed outside. If I'm wrong please correct me, also please explain.
Upvotes: 0
Views: 86
Reputation: 4425
When you submit the html form
the inputs inside the tag form will be sents to the url in the action attribute of the form and the input that are outside of the form will be ignored because he are not in the same environment/context.
Some docs about form
tag here
Regards
Upvotes: 1
Reputation: 151
The values outside the form tag won't be read.
HTML is a Markup Language which works based on parent child tags/nodes. So this necessary as there can be multiple forms and many input fields nested in the same file.
JQuery
If using jquery, please use an id for the form tag and use it to read the fields
Upvotes: 0
Reputation: 123
The input value outside the form will not be read because it is outside the form. The form encompasses only the elements inside the <form>
and </form>
tags.
Upvotes: 0