Have html select always show same option

Spacemoose

I want my select element to always show the same Text, no matter which option is selected. How would i do that?

<select>
  <option defaultValue disabled>
    Add library
  </option>
  <option value="code.jquery.com/jquery-3.1.0.js">
    JQuery 3.1.0
  </option>
  <option value="https://cdn.jsdelivr.net/lodash/4/lodash.min.js">
    lodash 4.x
  </option>
  <option value="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.js">
    RequireJS
  </option>
</select>

vrintle

Just take the initial value and store it in a variable. And then, whenever the change event on select is called re-assign the previous value to the select.

var select = document.querySelector('select');
var value = select.value;

select.addEventListener('change', function(event) {
  select.value = value;
  console.log('changed');
});
<select>
  <option defaultValue disabled>
    Add library
  </option>
  <option value="code.jquery.com/jquery-3.1.0.js">
    JQuery 3.1.0
  </option>
  <option value="https://cdn.jsdelivr.net/lodash/4/lodash.min.js">
    lodash 4.x
  </option>
  <option value="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.js">
    RequireJS
  </option>
</select>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Show value of select option in html

HTML select option show list after first select option selected

How to show disable HTML select option in by default?

Multiple select form tag for the same name getting the last option always

Select option from dropdown menu and show data about it on the same page

Select Option hide and show

Show/Hide HTML Table Columns using SELECT option

Is it possible to use JS to open an HTML select to show its option list?

Unable to show HTML select option initially when starting the page in Angular

HTML Select tag show vertical scroll with 10 option

How can I add alert button to the radio option if I have multiple select tags with same option?

How to show alert when we select the same option form select box

Unable to select an option from drop down as i have 2 drop down with the same '<select class=

How to remove a selected option from another select tag when i have five select with same options and values?

How to get selected value in one select option and based on that, fetch data from MySQL table to show another select option in the same form

show option count in dependent select

Show div on select dropdown option

show icon first select option

Select option does not show data

How to tell Click to always show option defaults

Select option html in JavaScript

html select option separator

HTML select option with EJS

Html Select option Underline

HTML <select> default option

html select option javascript

Select option for a form in html

React : why I have to click twice on the same option to set in select box

show select option depends on button select

TOP Ranking

HotTag

Archive