3

Is There a way To set selected="selected" to selected="notselected" Or something like that. i tried selected="false" but it did not doing anything

Thank You For all your answers

The Beast
  • 1
  • 1
  • 2
  • 24
  • So this goes like. A **select tag** *is like a* **radio button group**, but in this case the **options** *are* the **radio button**. Only one of them can be selected at the time. So if you set one to selected the previous selection get automatically unselected. *there is an special case* in which this does not happen and it is when a select tag has the multiple selection set, in which case you can select 1 or more options. – T04435 Nov 18 '15 at 05:58
  • Does this answer your question? [What does it mean in HTML 5 when an attribute is a boolean attribute?](https://stackoverflow.com/questions/4139786/what-does-it-mean-in-html-5-when-an-attribute-is-a-boolean-attribute) – miken32 Apr 28 '23 at 15:26

4 Answers4

5

You can do it easily with little bit jquery. Please have a look the demo jsfiddle Demo

Markup:

<select multiple="multiple" name="remaintextarea" id="studentremain" size="10">
 <option value="one">One</option>
 <option value="two">Two</option>
 <option value="three">Three</option>
</select>
<button type='button' id='selectall'>Select All</button>
<button type='button' id='deselectall'>De-Select All</button>

JS:

$('#selectall').click(function() {
$('#studentremain > option').attr("selected", "selected");
});   

$('#deselectall').click(function() {
$('#studentremain > option').removeAttr("selected");
 });
Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72
2

Just don't specify selected for the options you don't want selected:

 <select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi" selected>Audi</option>
</select> 
Sean Cox
  • 782
  • 1
  • 5
  • 12
  • yes. In the above code, Audi will be the option that is selected. If you move selected to one of the other options then it would be selected. – Sean Cox Nov 18 '15 at 05:35
2

This may help

  <select>
  <option disabled selected> -- select an option -- </option>
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
  </select>
jmr333
  • 183
  • 1
  • 9
  • -- select an option -- Will be displayed by default. But if you chose an option,you will not be able select it back – jmr333 Nov 18 '15 at 05:39
  • so disabled will make it so that it is no longer selected right? – The Beast Nov 18 '15 at 05:46
  • No disable will not allow user to select that option once they click anything else. Read the comment on the question you will get a better idea. – T04435 Nov 18 '15 at 06:02
2

You use selected property in html then it will select the one you added selected on just like this

<option value="bike" selected></option>