Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript change select element

// Selecting the 3rd option (Demo 2)
document.querySelector('#mySelect').querySelector('option')[2].selected = 'selected'
Comment

javascript select change selected

const options = Array.from(select.options);
options.forEach((option, i) => {
  if (option.value === use_id) select.selectedIndex = i;
});
Comment

javascript change select element

// Selecting the 3rd option (Demo 2)
const $select = document.querySelector('#mySelect');
$select.value = $select.querySelector('option')[2].value;
Comment

How do I change an HTML selected option using JavaScript?

<a href="javascript:void(0);" onclick="selectItemByValue(document.getElementById('personlist'),11)">change</a>

function selectItemByValue(elmnt, value){

  for(var i=0; i < elmnt.options.length; i++)
  {
    if(elmnt.options[i].value === value) {
      elmnt.selectedIndex = i;
      break;
    }
  }
}
Comment

change on select with javascript

$("#select1").change(function() {
  if ($(this).data('options') === undefined) {
    /*Taking an array of all options-2 and kind of embedding it on the select1*/
    $(this).data('options', $('#select2 option').clone());
  }
  var id = $(this).val();
  var options = $(this).data('options').filter('[value=' + id + ']');
  $('#select2').html(options);
});
Comment

javascript change select element

// Selecting the 3rd option (Demo 2)
const $select = document.querySelector('#mySelect');
$select.value = $select.querySelector('option')[2].value;
Comment

javascript change select element

// Selecting the 3rd option (Demo 2)
document.querySelector('#mySelect').querySelector('option')[2].selected = 'selected'
Comment

javascript change select element

// Selecting the 3rd option (Demo 2)
const $select = document.querySelector('#mySelect');
$select.value = $select.querySelector('option')[2].value;
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser2 align text center 
Javascript :: removeitem localstorage 
Javascript :: javascript trigger function when element is in viewport 
Javascript :: Remove duplicate items in an array 
Javascript :: express.js hello world 
Javascript :: framer motion nextjs 
Javascript :: react router dom props.history is undefined 
Javascript :: DC League of Super-Pets 
Javascript :: array map 
Javascript :: js scroll to bottom exact 
Javascript :: import leaflet js 
Javascript :: Get Keys Of JSON As Array 
Javascript :: jquery timer countdown 
Javascript :: js replace 
Javascript :: setimeout 
Javascript :: javascript round 
Javascript :: array pop 
Javascript :: how to check what browser you are using 
Javascript :: npm set author name 
Javascript :: react-router-dom routes 
Javascript :: javascript get cell by index 
Javascript :: how do you swap the vaRIables js 
Javascript :: svg css viewbox 
Javascript :: Update select2 after removing an element 
Javascript :: add val in data-id jquery 
Javascript :: mysql JSON_SEARCH LIKE 
Javascript :: react currency format method 
Javascript :: or operator js 
Javascript :: coderbyte first factorial solutions 
Javascript :: document style 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =