Home > database >  Failed to use the checked attribute with <select multiple></select>
Failed to use the checked attribute with <select multiple></select>

Time:07-11

I waned to use the checked attribute with a <select multiple></select> but the checked attribute didn't work. I don't know what I did wrong

<body>
<form action="" method="get">
    <fieldset>
        <label for="skill">Skill</label>
        <select name="skills" id="skill" multiple>
            <option checked value="html">Html</option>
            <option value="css">Css</option>
            <option value="jss">Javascript</option>
        </select>
        <br>
        <input type="submit">
        <input type="reset">
    </fieldset>
</form>

The output in the browser

Thank you

CodePudding user response:

<option checked> should be <option selected>, as this is an option, not a checkbox

CodePudding user response:

Use below code in order to work

    <form action="/">
  <label for="skills">Skill</label>
  <select name="skills" id="skills" multiple>
    <option value="volvo">Html</option>
    <option value="Css">Css</option>
    <option value="Javascript">Javascript</option>
  </select>
  <br><br>
  <input type="submit" value="Submit">
</form>

Hold down the Ctrl (windows) or Command (Mac) button to select multiple options.

  •  Tags:  
  • html
  • Related