I have below html code
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<br>
<span class="anchor">Select Fruits</span>
<ul class="items">
<li><input type="checkbox" />Apple </li>
<li><input type="checkbox" />Orange</li>
<li><input type="checkbox" />Grapes </li>
<li><input type="checkbox" />Berry </li>
<li><input type="checkbox" />Mango </li>
<li><input type="checkbox" />Banana </li>
<li><input type="checkbox" />Tomato</li>
</ul>
<br><br>
<input type="submit" value="Submit">
</form>
Output is shown as below in html
When I submit the form fruit selection options are not shown. I am getting output as cars=volvo. How to get check box selection? What is the bug?
Thanks for your time
2
Answers
Try adding a name and a value attribute on every checkbox like so :
and so on…
$_GET[‘fruit’] will return an array consisting of all the values of the checkboxes that were checked.
When creating forms, every form input requires a "name" attribute. For example: