Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get the value or text from select element using javaScript

<select id="ddlViewBy">
  <option value="1">test1</option>
  <option value="2" selected="selected">test2</option>
  <option value="3">test3</option>
</select>
Running this code:

var e = document.getElementById("ddlViewBy");
var strUser = e.value;
Would make strUser be 2. If what you actually want is test2, then do this:

var e = document.getElementById("ddlViewBy");
var strUser = e.options[e.selectedIndex].text;
Comment

get text from selected select javascript object

this.options[this.selectedIndex].text
Comment

PREVIOUS NEXT
Code Example
Javascript :: Angular ion-search 
Javascript :: js get seconds difference 
Javascript :: javascript check if file exists on server 
Javascript :: crypto node 
Javascript :: Replace With Alphabet Position 
Javascript :: when a form is subbmited jquery 
Javascript :: local string method 
Javascript :: react native svg onpress 
Javascript :: which methods do not have the hook equivalents in reactjs 16.8++ 
Javascript :: foreach object javascript 
Javascript :: on change field text jquery 
Javascript :: javascript string starts with 
Javascript :: nodejs https server 
Javascript :: javascript string format 
Javascript :: move element jquery 
Javascript :: add active class to li onclick react 
Javascript :: javascript get all child elements 
Javascript :: js random numbers 
Javascript :: nodejs fs delete non empty directory 
Javascript :: How to Set Active Tab in jQuery Ui 
Javascript :: addition of two matrix in javascript 
Javascript :: append array js 
Javascript :: passing state in link react 
Javascript :: vowel 
Javascript :: electron mass to amu 
Javascript :: js concat variable and string 
Javascript :: falsy value javascript 
Javascript :: font awesome react native icons 
Javascript :: how to launch several async functions in node js 
Javascript :: javascript copy image to clipboard 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =