PDA

View Full Version : Form Input Value



leroycjw
May 21st, 2016, 08:28 AM
For example...
if input type is radio
<input type="radio" name="gender" value="male" />Male <br />
<input type="radio" name="gender" value="female" />Female <br />

if input type is checkbox
<input type="checkbox" name="gender" value="1" />Male <br />
<input type="checkbox" name="gender" value="2" />Female <br />

What does the value stand for?

why if the input type is check box the value is = "1", "2" etc but why not male and female like radio type attribute?

VIPStephan
May 21st, 2016, 11:27 AM
It doesn’t actually matter; it’s a matter of personal preference. The value is sent to the script that is processing the form and usually used for an if/else condition. There you either check “if([input name] === 'male') {do something}” or “if([input name] === 2) {do something}”. The value can be whatever you like.

Note, however, that checkboxes allow multiple selections while radio buttons are mutually exclusive. Setting the current gender debate aside, you can only be one gender, so checkboxes aren’t the appropriate elements for this selection. Also, for that same reason checkboxes cannot have the same name (unless you use a name as array, but that’s for another lesson).