Answers for "javascript select option"

1

javascript get all select options

var options = document.getElementById('mySelectID').options;
for (let i = 0; i < options.length; i++) { 
  console.log(options[i].value);//log the value
}
Posted by: Guest on August-05-2019
1

make select option selected javascript

document.getElementById('personlist').getElementsByTagName('option')[11].selected = 'selected'
Posted by: Guest on October-07-2020
1

get index of selected option javascript

$("#sel").attr("selectedIndex")
// or
$("#sel")[0].selectedIndex
//or
$(this).prop('selectedIndex')
Posted by: Guest on October-28-2020
2

use js to get select value

// reference to 'scripts' select list 
// used throughout the examples below
var sel = document.getElementById('scripts');

// display value property of select list (from selected option)
console.log( sel.value );
Posted by: Guest on February-22-2020
0

options in html

<form id="form">
            <label for=""></label>
            <br>
            <input type="" id="">
            <br>
            <label for=""></label>
            <br>
            <input list="browsers" name="Thenicknamey" id="Thenickname">
            <datalist id="browsers">
                <option value=""></option>
                <option value=""></option>
                <option value=""></option>
            </datalist>
            <br>
            <label for=""></label>
            <br>
            <input type="" id="">
            <br>
            <input type="" id="">
        </form>
Posted by: Guest on October-10-2020
0

js select option in form

<form name="AddAndEdit">
   <select name="list" id="personlist">
      <option value="P1">Person1</option>
      <option value="P2">Person2</option>
      <option value="P3">Person3</option>
   </select>
</form>
Posted by: Guest on July-10-2020

Code answers related to "javascript select option"

Browse Popular Code Answers by Language