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

select text with javascript

// highlight text in an input element
element.select();

// highlight a portion of an element
// element.setSelectionRange(start, end, ?direction)
// start, end - start and end indices of the new selection
// direction (optional) - "forward", "backward", or "none" (default)
element.setSelectionRange(3, 5);
Comment

javascript select text in element

// Select text in element 'elm'
const elm = document.getElementById('elm');

// Clear any current selection
const selection = window.getSelection();
selection.removeAllRanges();

// Select paragraph
const range = document.createRange();
range.selectNodeContents(elm);
selection.addRange(range);
Comment

get text selection javascript

function getSelectionText() {
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    return text;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to set env variables in js 
Javascript :: JavaScript String startsWith() examples 
Javascript :: create node js api 
Javascript :: javascript write to text file 
Javascript :: get name of input jquery 
Javascript :: object clone javascript 
Javascript :: promisify 
Javascript :: hmac_sha256 node 
Javascript :: javascript format date to dd-mm-yyyy 
Javascript :: poo js 
Javascript :: axios get with headers 
Javascript :: string json to class c# 
Javascript :: react current path 
Javascript :: change css with javascript 
Javascript :: toastr 
Javascript :: javascript button add input to list item 
Javascript :: get all days of month javascript 
Javascript :: force click btn using jquery 
Javascript :: byte to mb js 
Javascript :: javascript calculator 
Javascript :: javascript json deserialize 
Javascript :: componentwillunmount 
Javascript :: copy link to clipboard 
Javascript :: javascript get sub array 
Javascript :: how to get file type in javascript 
Javascript :: javascript throw new error 
Javascript :: javascript loop object 
Javascript :: mongodb mongoose update an element in an array of objects 
Javascript :: format date javascript 
Javascript :: localstorage try catch 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =