Hello, thanks for taking the time to read my question! I am a bit lost on the difference between value=" " and name=" ". I am on the radio lesson of the HTML course: https://www.codecademy.com/courses/learn-html/lessons/html-forms/exercises/radio-button-input. I notice that the name attribute groups together the for input sections and the value attribute reflect the label. Can someone explain exactly why these two are used? I do not understand the use of the name attribute to group these together. Why must there be a value attribute when the label already states the topping ? Hopefully this makes sense!
Hello @rayxpelton, welcome to the forums! The
name attribute is used in backend (PHP, Some JS, etc)- or in the frontend with JS. It is used to get the value of a form. So, when you’re working with forms in the other languages, you use the
name attribute to identify the specific radio/checkbox/textarea, etc.
Sometimes you need a value, and sometimes you don’t. When you use a
radio, for example, the
name identifies that radio button, but the
value is its value; the value that the frontend/backend code uses.
In some forms-such as
value is set to whatever is inputted by the user. The
name is still defined in the same way.
I hope this helps!
Thanks @codeneutrino ! That does help. So does the ID attribute and the Name attribute have anything in relation?
Not really. The
id can be used in CSS and JS to add movement to the webpage. The
name attribute is connected to form handling. You could just as well have:
<input type="radio" name="something" id="somethingdifferent">
Thanks again for your help! Definitely cleared things up for me. It’s all slowly starting to make more sense.