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
}
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
}
make select option selected javascript
document.getElementById('personlist').getElementsByTagName('option')[11].selected = 'selected'
get index of selected option javascript
$("#sel").attr("selectedIndex")
// or
$("#sel")[0].selectedIndex
//or
$(this).prop('selectedIndex')
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 );
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>
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>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us