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

PREVIOUS NEXT
Code Example
Javascript :: array.push 
Javascript :: express prisma 
Javascript :: javascript basic function 
Javascript :: how to use json stringify in javascript 
Javascript :: nodejs create stream 
Javascript :: js environment variables 
Javascript :: javascript check if string ends with space 
Javascript :: instanceof javascript 
Javascript :: chrome block javascript alert 
Javascript :: end session express 
Javascript :: accordion reatjs 
Javascript :: jest mock mockname 
Javascript :: how can hide link from inspect element 
Javascript :: javascript loop 
Javascript :: js reduce 
Javascript :: create an empty array js 
Javascript :: getboundingclientrect 
Javascript :: why does javascript have hoisting 
Javascript :: node save wav base64 
Javascript :: express route parameters 
Javascript :: inline javascript modules 
Javascript :: how to create a slice of the array with n elements taken from the beginning in javascript 
Javascript :: push in object javascript 
Javascript :: query string to object javascript 
Javascript :: discord.js set role permissions for all channels 
Javascript :: UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON 
Javascript :: jquery select element without child 
Javascript :: how to delete everything from a folder in js 
Javascript :: pdf.js extract text 
Javascript :: jquery slide 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =