+ 3
The use of "name" and "value" in html forms
I have started my html course and while studying the "form" part, I saw there were "name" and "value" attributes next to the input tag. What use do they serve and how many different sub-divisions of them are there?
4 Answers
+ 4
Well, when you use the name attribute it is the âkeyâ to that input tag. Letâs say, you have the following HTML:
<input type="text" name="username"/>
so when the user types into that, it is actually changing the value attribute. So when you submit the form, if using the GET method (where the data is visible in the website URL), then it will be like this: www.example.com/ACTION_ATTRIBUTE_OF_FORM_TAG?username=USER_VALUE . If you changed the name attribute of the HTML tag, then the URL key would change. Letâs say, you have another input tag where type="number" and name="age", then the query string (the bit after the ?) would be this: username=USER_VALUE_FOR_USERNAME&age=USER_INPUT_FOR_AGE .
+ 3
1. name attribute is used to get value from that particular tag or element or access particular tag or element
2. value attribute is used to assign value to a particular element or tag
Example : <button name="btn1" value="Submit">
Here, btn1 will be used to perform action when the button is clicked or hover or anything else whereas Submit is the value that appears on the button.
+ 2
name attribute is used to get value from form and used or processed by server side script example JSP
value is used to assign default value to particular component in html form