jquery indexOf problem with IE
Posted
by
user441365
on Stack Overflow
See other posts from Stack Overflow
or by user441365
Published on 2011-01-15T16:40:22Z
Indexed on
2011/01/15
16:53 UTC
Read the original article
Hit count: 104
jQuery
Hi,
I have a multiple select field and a jquery function that checks for a change in the select. the function looks for the value "Other", and if it's selected then displays an extra text field.
This is all working fine in chrome and FF, but for some reason IE throws an error on the indexOf function "Object doesn't support this property or method".
Any help would be much appreciated.
Here's the code:
<select name="test" multiple="multiple" id="test">
<option value="one">one</option>
<option value="two">two</option>
<option selected="selected" value="Other">Other</option>
</select>
<input name="Name_Other" type="text" id="Name_Other" class="OtherDisplay" />
$.toggleOther = function (dd, txtOther) {
if ($(dd).val() == null || $(dd).val().indexOf("Other") != 1)
$(txtOther).hide();
$(dd).change(function () {
var sel = $(this).val();
if (sel != null && sel.indexOf("Other") != -1) {
$(txtOther).show();
}
else {
$(txtOther).hide();
}
});
}
$.toggleOther("#test", ".OtherDisplay");
© Stack Overflow or respective owner