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

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 :: http status code 406 
Javascript :: discord.js bot presence 
Javascript :: regex more than one character 
Javascript :: how to push values in array 
Javascript :: delay / sleep program in js 
Javascript :: button ref react 
Javascript :: getinitialprops to a hoc in next js 
Javascript :: postfix date javascript 
Javascript :: jqerrt get all img alt from string 
Javascript :: highlight link javascript 
Javascript :: noscript tag code string in react 
Javascript :: angular two way binding 
Javascript :: javascript match against array 
Javascript :: arguments in javascript 
Javascript :: json ld product schema 
Javascript :: array con doble javascript 
Javascript :: js show element 
Javascript :: run javascript in flutter 
Javascript :: how to assert input value in testing library 
Javascript :: div goind down 
Javascript :: javascript const 
Javascript :: underline unused code vscode 
Javascript :: javascript array erstellen 
Javascript :: filtering in javascript 
Javascript :: show ad on facebook game 
Javascript :: (node:3644) UnhandledPromiseRejectionWarning: TypeError [EMOJI_TYPE]: Emoji must be a string or GuildEmoji/ReactionEmoji 
Javascript :: jest mock call 
Javascript :: find saturday with moment js 
Javascript :: how to check if date is between two dates in javascript 
Javascript :: phaser create animation from sprite sheet 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =