Jordi P.S.
Jordi P.S.

Reputation: 4018

jQuery val() returns an array with IE8 on select/option element

The following alert returns "string" in the majors browsers. Returns "object" (an array of one element) on <=IE8.

HTML:

<SELECT id="adults_1" type="select">
    <OPTION value="1">1 persona</OPTION>
</SELECT>​

JS:

 alert(typeof $("#adults_1").val()); 

JsFiddle: http://jsfiddle.net/JM9AY/2/

Is it a bug or it is the expected value? If it's a bug, is there a workaround?

Upvotes: 3

Views: 1435

Answers (1)

Jon
Jon

Reputation: 437356

Removing type="select" corrects this unexpected behavior. What is the meaning of the type attribute here in any case? There is no such attribute in HTML5.

Upvotes: 8

Related Questions