21
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.

4

2 回答 2

33

尝试这个

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);
}

演示

于 2012-12-06T22:19:48.180 回答
14

基于快速JSFiddle,该selectedOptions集合尚未得到广泛支持。

失败/不支持:

  • IE10(桌面或地铁)
  • IE11
  • 野生动物园 7
  • iOS6 Opera Mini
  • 安卓4.0.4浏览器
  • 安卓 4.0.4 火狐浏览器

作品:

  • 铬 23.0.1271.95
  • 歌剧 12.11
  • 黑莓 10 浏览器
  • iOS6 Safari
  • iOS6 铬
  • Android 4.0.4 Opera 移动浏览器
  • 火狐 53.0
  • 边缘
于 2012-12-06T22:14:58.857 回答