+ 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?

19th Jan 2019, 6:49 AM
Jerwin
Jerwin  - avatar
4 Respuestas
+ 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 .
19th Jan 2019, 7:26 AM
Rowsej
Rowsej - avatar
19th Jan 2019, 9:35 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 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.
20th Jan 2019, 8:19 AM
Akshay Madrikar
Akshay Madrikar - avatar
+ 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
19th Jan 2019, 7:11 PM
sree harsha
sree harsha - avatar