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

how to get text from select tag in javascript

<select id="box1" onChange="myNewFunction(this);">
  <option value="98">dog</option>
  <option value="7122">cat</option>
  <option value="142">bird</option>
</select>
<script>
  function myNewFunction(sel) {
  alert(sel.options[sel.selectedIndex].text);
}
</script>
Comment

get text from selected select javascript object

this.options[this.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

javascript get selected text

const getSelectedText = () => window.getSelection().toString();

getSelectedText();
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 :: use local storage on server with node 
Javascript :: How to fix stomp websocket error 
Javascript :: convert number to string date js 
Javascript :: http get request js 
Javascript :: javascript for loop starting from end 
Javascript :: set stroke color canvas 
Javascript :: js string check case 
Javascript :: js array sum 
Javascript :: javascript order array by date 
Javascript :: How to access the request body when POSTing using Node.js and Express 
Javascript :: google sign up react npm 
Javascript :: number to binary javascript 
Javascript :: style before javascript 
Javascript :: create array javascript numbers 
Javascript :: document.write multiple lines 
Javascript :: node js run bat file 
Javascript :: react js empty build 
Javascript :: how to check if a message has an attachment discord js 
Javascript :: bootstrap carousel click event next previous 
Javascript :: send file discord js v12 
Javascript :: local storage javascript 
Javascript :: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 
Javascript :: javascript convert string to number or integer 
Javascript :: call function in javascript from html 
Javascript :: js domtokenlist to array 
Javascript :: js wait 
Javascript :: javascript for loop infinite 
Javascript :: FAILURE: Build failed with an exception react native android 
Javascript :: js div detect change 
Javascript :: difference between type and method in ajax 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =