skip to Main Content

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

enter image description here

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


  1. Try adding a name and a value attribute on every checkbox like so :

    <input type="checkbox" name="fruit[]" value="Apple" />
    

    and so on…

    $_GET[‘fruit’] will return an array consisting of all the values of the checkboxes that were checked.

    Login or Signup to reply.
  2. When creating forms, every form input requires a "name" attribute. For example:

    <input type="text" name="nom" placeholder="Type your name here">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search