最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - this.value is working on Firefox, but not in Internet Explorer? - Stack Overflow

programmeradmin1浏览0评论

I have an onChange event on a select.

When I do an alert(this.value), it's working on Firefox, but not on Internet Explorer. Why not?

This is the code:

<select onchange="new Ajax.Updater('fiches', '/~project/index.php/folder/fiche', {asynchronous:true, evalScripts:true, parameters:'fiche=' + this.value});" class="input" id="fiche" name="fiche">
  <option value="0">Choisir ma fiche</option>
  <option value="1">Vous etes salariés</option>
  <option value="2">Sans emploi</option>
</select>

I have an onChange event on a select.

When I do an alert(this.value), it's working on Firefox, but not on Internet Explorer. Why not?

This is the code:

<select onchange="new Ajax.Updater('fiches', '/~project/index.php/folder/fiche', {asynchronous:true, evalScripts:true, parameters:'fiche=' + this.value});" class="input" id="fiche" name="fiche">
  <option value="0">Choisir ma fiche</option>
  <option value="1">Vous etes salariés</option>
  <option value="2">Sans emploi</option>
</select>
Share Improve this question edited Jul 23, 2010 at 7:45 Andrei Dziahel 9695 silver badges14 bronze badges asked Jul 16, 2010 at 12:05 bahamut100bahamut100 1,8377 gold badges28 silver badges40 bronze badges 3
  • 1 Please add your HTML and JavaScript code to the question, otherwise we're looking for a needle in a haystack here. – Prutswonder Commented Jul 16, 2010 at 12:08
  • I'm not familiar with symfony but is "new Ajax.Updater(...);" a valid constructor? e.g. is "Ajax" the object you want to instanciate and thus "new Ajax().Updater(...);" might work better? – scunliffe Commented Jul 16, 2010 at 13:01
  • "new Ajax.Updater(...);" is correct (generated automatically by a symfony function) – bahamut100 Commented Jul 16, 2010 at 13:03
Add a ment  | 

3 Answers 3

Reset to default 3

I have had similar problems in the past with IE and selects. The value property of select items is a pain in IE. Usually the solution is to care about the selected option (not the select element) and access to its text attribute.

I'll do this in jQuery to access the text selected:

$("#my_select_item option:selected").text()

So, in raw JavaScript it should be something like:

document.getElementById("myselect").options[document.getElementById("myselect").selectedIndex)].text

or

document.getElementById("myselect").options[document.getElementById("myselect").selectedIndex)].value

That is the general idea to make selects + JS happen in IE.

Try this.options[this.selectedIndex].value.

It looks like you're using Prototype. Try calling $F(this) rather than this.value.

发布评论

评论列表(0)

  1. 暂无评论