{"action":"created","issue":{"url":"https://api.github.com/repos/jquery/jquery/issues/2562","labels_url":"https://api.github.com/repos/jquery/jquery/issues/2562/labels{/name}","comments_url":"https://api.github.com/repos/jquery/jquery/issues/2562/comments","events_url":"https://api.github.com/repos/jquery/jquery/issues/2562/events","html_url":"https://github.com/jquery/jquery/issues/2562","id":104044070,"number":2562,"title":"Select multiple will return null when no values returned","user":{"login":"DataTables","id":278219,"avatar_url":"https://avatars.githubusercontent.com/u/278219?v=3","gravatar_id":"","url":"https://api.github.com/users/DataTables","html_url":"https://github.com/DataTables","followers_url":"https://api.github.com/users/DataTables/followers","following_url":"https://api.github.com/users/DataTables/following{/other_user}","gists_url":"https://api.github.com/users/DataTables/gists{/gist_id}","starred_url":"https://api.github.com/users/DataTables/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataTables/subscriptions","organizations_url":"https://api.github.com/users/DataTables/orgs","repos_url":"https://api.github.com/users/DataTables/repos","events_url":"https://api.github.com/users/DataTables/events{/privacy}","received_events_url":"https://api.github.com/users/DataTables/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jquery/jquery/labels/Needs%20review","name":"Needs review","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-08-31T12:23:17Z","updated_at":"2015-09-01T15:18:04Z","closed_at":null,"body":"I've just been looking into an issue whereby if you have a `select` element with the `multiple` option set and no options selected `$().val()` will return `null` rather than an empty array. If one more more items are selected, then it returns an array. I would have expected that an empty array would have been returned in this case.\r\n\r\n[This fiddle shows the issue](http://jsfiddle.net/jzyyhosx/). IT appears all the way back to jQuery 1.2 where multiple value support was added.\r\n\r\nThe reason an empty array is not returned is the check for `elem.selectedIndex` being < 0 [here](https://github.com/jquery/jquery/blob/master/src/attributes/val.js#L87). While I understand that for a single select, I don't while get why that would be done for a multi-select.\r\n\r\nRemoving `|| index < 0` would allow the empty array to be returned.\r\n\r\nHaving said that, I'm not really expecting this change to be made as I guess a number of sites will depend upon this behaviour. I'm more wondering if someone might be willing to say why it is done this way? I've searched this issue tracker and the bugs.jquery.com site, but couldn't find any mention of it."},"comment":{"url":"https://api.github.com/repos/jquery/jquery/issues/comments/136757448","html_url":"https://github.com/jquery/jquery/issues/2562#issuecomment-136757448","issue_url":"https://api.github.com/repos/jquery/jquery/issues/2562","id":136757448,"user":{"login":"gibson042","id":1199584,"avatar_url":"https://avatars.githubusercontent.com/u/1199584?v=3","gravatar_id":"","url":"https://api.github.com/users/gibson042","html_url":"https://github.com/gibson042","followers_url":"https://api.github.com/users/gibson042/followers","following_url":"https://api.github.com/users/gibson042/following{/other_user}","gists_url":"https://api.github.com/users/gibson042/gists{/gist_id}","starred_url":"https://api.github.com/users/gibson042/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gibson042/subscriptions","organizations_url":"https://api.github.com/users/gibson042/orgs","repos_url":"https://api.github.com/users/gibson042/repos","events_url":"https://api.github.com/users/gibson042/events{/privacy}","received_events_url":"https://api.github.com/users/gibson042/received_events","type":"User","site_admin":false},"created_at":"2015-09-01T15:18:04Z","updated_at":"2015-09-01T15:18:04Z","body":"That block of code doesn't even need to change because `null` and empty-array `val` yield identical results. But returning empty string there would definitely be incorrect."}}