Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

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 :: react and react dom cdn 
Javascript :: text field material ui max input for number 
Javascript :: how to get class name in jquery 
Javascript :: how to select div js 
Javascript :: nodejs how to send html 
Javascript :: javascript break out of loop 
Javascript :: jquery active menu 
Javascript :: average function for javascript 
Javascript :: how to get attr in vuejs 
Javascript :: Regex get emojis 
Javascript :: jquery insert after element 
Javascript :: jquery navigation 
Javascript :: javascript get parent by tag 
Javascript :: cancel axios request 
Javascript :: react function being called every minute 
Javascript :: javascript cancel timeout 
Javascript :: react text input onchange 
Javascript :: remove char from string js 
Javascript :: distance to km javascript 
Javascript :: react.fragment react native 
Javascript :: vs code shows bodyparser deprecated 
Javascript :: js map array to dictionary 
Javascript :: moment get start of week in datetime 
Javascript :: event delegation in javascript 
Javascript :: react app js 
Javascript :: dataset js 
Javascript :: urlencoded limit express 
Javascript :: js date yyyy-mm-dd 
Javascript :: join a list of strings into one string javascript 
Javascript :: setinterval js 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =