Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selectedOptions[0].textContent; not working in IE or Firefox

function call(op) {
    var x = op.selectedOptions[0].textContent;
    var n = x.substring(0, 3);
    //alert(n);
    document.pts.inputbox.value = n;
    document.pts.submit();
}

I have a function that grabs the label value from a selected option in a list box, then it disects out the first 3 letters and passes that information on to an input box value.

The issue is with how the js is grabbing the selected options label text content. It seems to work in Chrome just fine, but in firefox17 and IE9 nothing happens. Any suggestions on a better way to get the selected options label value?

EDIT: I can NOT use the options value, that value is reserved for something more specific Everything works fine in JSfiddle.

like image 576
user1868232 Avatar asked Dec 06 '12 21:12

user1868232


2 Answers

Try this

function call(op) {
    var x = op.options[op.selectedIndex].text;
    var n = x.substring(0, 3);
    alert('Index : '+op.selectedIndex+' and first 3 lettrs are : '+n);
}

DEMO.

like image 184
The Alpha Avatar answered Nov 15 '22 11:11

The Alpha


Based on a quick JSFiddle, the selectedOptions collection isn't widely supported yet.

Fails/Unsupported:

  • IE10 (Desktop or Metro)
  • IE11
  • Safari 7
  • iOS6 Opera Mini
  • Android 4.0.4 Browser
  • Android 4.0.4 Firefox Browser

Works:

  • Chrome 23.0.1271.95
  • Opera 12.11
  • BlackBerry 10 Browser
  • iOS6 Safari
  • iOS6 Chrome
  • Android 4.0.4 Opera Mobile Browser
  • Firefox 53.0
  • Edge
like image 33
scunliffe Avatar answered Nov 15 '22 09:11

scunliffe