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
3 Answers
Reset to default 3I 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
.