select text with 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>

4
1
Krish 100200 points

                                    // 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) - &quot;forward&quot;, &quot;backward&quot;, or &quot;none&quot; (default)
element.setSelectionRange(3, 5);

4 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript select text get selection text javascript js text selection div text select javascript javascript selected option text select text box js select text javascirpt select text in javacript javascript select selected option text js get text content select select text in input javascript how to get text from select option in js select text in a tag js selecting text in js javascript select option by text javascript select html text select text in javascript from an element js select based on text javascript get text from selected option get text of select javascript javascript select input text javascript select option with text javascript select value and text selection text javascript get the text from select javascript get the text from select javascripot javascript select option this.text select div text javascript javascript get text select javascript get text selecte select text with js select text on p element in js how to select text js js select element based on text javascript select drop down option by text select box text javascript js select text in dom javascript select by text javascript get select option text how to get text from selected option javascript how to find select text in javascript select element by text javascript js get text of select option js get text select from div js get text select from content select text in page js select text in pagejs select html get select text how to read selected text of option in select js javascript text selection select a text in javascript js select text select text in div javascript select text in javascript js select input text js select text in input javascript select get option text jvavascript select text option select text using javascript js select get text select text input javascript select text javascript javascript selecting based on text javascript how to select text in div get text from selection javascript html select box selected text in javascript select Text from to js select Text js js select option text how to select text in input javascript javascript to select text javascript select option text javascript select element with text javascript select text input selection option text in javascript select text with javascript get text from select option javascript how to get select option text in javascript javascript select option[text= javascript select option based on text how to get text from select tag in javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source