10 examples of 'javascript get selected option text' in JavaScript

Every line of 'javascript get selected option text' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
82function getSelectedText() {
83 if (window.getSelection) {
84 return window.getSelection().toString();
85 } else if (document.selection && document.selection.type !== "Control") {
86 return document.selection.createRange().text;
87 }
88 return "";
89}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

193function getSelectedOptionsStr() {
194 var options_str = '';
195 var $selectedOptions = $('li[aria-selected="true"]', $lbox);
196 if ($selectedOptions.length > 0) {
197 $selectedOptions.each(function() {
198 options_str += $(this).text() + ', ';
199 });
200 options_str = options_str.slice(0, -2);
201 $cbox.addClass('selections');
202 $togglebutt.hide();
203 $clearbutt.show();
204 } else {
205 options_str = $cbox.attr('aria-label');
206 $cbox.removeClass('selections');
207 $clearbutt.hide();
208 $togglebutt.show();
209 }
210 return options_str;
211}
1function getSelectedText() {
2 var text = "";
3 if (window.getSelection) {
4 text = window.getSelection().toString();
5 } else if (document.selection && document.selection.type != "Control") {
6 text = document.selection.createRange().text;
7 }
8 return text;
9}
37function getSelectedText() {
38 if (window.getSelection) {
39 return window.getSelection().toString();
40 } else if (document.selection) {
41 return document.selection.createRange().text;
42 }
43 return '';
44};
66getSelectedOption(key) {
67 return this.$refs.select2.options[this.selectedIndex()].dataset[key];
68}
185function changeSel(selected)
186{
187 if (cat.selectedIndex === -1)
188 return;
189
190 if (cat.options[cat.selectedIndex].value.indexOf("/") > 0)
191 {
192 var i,
193 count = 0;
194
195 file.style.display = "inline";
196 file.disabled = false;
197
198 for (i = file.length; i >= 0; i -= 1)
199 file.options[i] = null;
200
201 for (i = 0; i < files.length; i++)
202 if (files[i].indexOf(cat.options[cat.selectedIndex].value) === 0)
203 {
204 var filename = files[i].substr(files[i].indexOf("/") + 1);
205 var showFilename = filename.substr(0, filename.lastIndexOf("."));
206 showFilename = showFilename.replace(/[_]/g, " ");
207
208 file.options[count] = new Option(showFilename, files[i]);
209
210 if (filename === selected)
211 {
212 if (file.options.defaultSelected)
213 file.options[count].defaultSelected = true;
214 else
215 file.options[count].selected = true;
216 }
217
218 count++;
219 }
220
221 if (file.selectedIndex === -1 && file.options[0])
222 file.options[0].selected = true;
223
224 showAvatar();
225 }
226 else
227 {
228 file.style.display = "none";
229 file.disabled = true;
230 document.getElementById("avatar").src = avatardir + cat.options[cat.selectedIndex].value;
231 document.getElementById("avatar").style.width = "";
232 document.getElementById("avatar").style.height = "";
233 }
234}
66function getSelected() {
67 let t = '';
68 if (window.getSelection) {
69 t = window.getSelection();
70 } else if (document.getSelection) {
71 t = document.getSelection();
72 } else if (document.selection) {
73 t = document.selection.createRange().text;
74 }
75 return t;
76
77}
215function isOptionSelected(option: DebugElement): boolean {
216 return option.classes[classes.optionsItemSelected];
217}
795function selectText() {
796 if (document.selection) {
797 var range = document.body.createTextRange();
798 range.moveToElementText(this);
799 range.select();
800 } else if (window.getSelection) {
801 var range = document.createRange();
802 range.selectNode(this);
803 window.getSelection().addRange(range);
804 }
805}
40getSelectedItemValueForSelect(value) {
41 const result = this.props.options.find((item) => item.option === value);
42 if (result) {
43 return value;
44 }
45 return ''; // it's custom
46}

Related snippets