+ 2

Question on Form element. <input>

why we give name and value in <input type="checkbox" or "radio" />

17th Jul 2017, 9:41 AM
Shubham
Shubham - avatar
1 Resposta
+ 5
'name' and 'value' are standard attributes of any form element: they are used as key/value pair plain text formated when submited to server... the purpose is to identify each values of a form data. Anyway, in html5 'name' is kept for compatibility, but it's advised to start using 'id' rather (good practice is to provide both with same value)... In case of checkbox and/or radio buttons, the 'value' attribute is mandatory, and the purpose is to give specific value to each options in a group (options with same 'name' value -- the 'id' way isn't suitable then): this really have sense only for radio button, wich provide a single-select way, while checkbox provide multi-select, but get some when receiving form data at server side (group of related checkbox are handled more easily)
17th Jul 2017, 10:06 AM
visph
visph - avatar