haltman
haltman

Reputation: 551

jquery prevent multi selection in multi-select

I everybody,

I've a multi-select like this:

<select multiple="multiple" id="lista">
    <option value="a">Mario</option>
    <option value="b">Maria</option>
    <option value="c">Mark</option>
</select>

How can I prevent to select multiple option by a user? (shift+arrow up/down)

thanks in advance

ciao h.

Upvotes: 2

Views: 1814

Answers (2)

Tom Walters
Tom Walters

Reputation: 15616

Although I'm not sure why you can't simply remove multiple="multiple" in the HTML, here's how you would do it with jQuery:

// Wait until the DOM is loaded
$(function(){
    $('#lista').removeAttr("multiple");
});

Upvotes: 2

Vitthal
Vitthal

Reputation: 546

You need to provide size attribute to it..

<select id="lista" size="3">
    <option value="a">Mario</option>
    <option value="b">Maria</option>
    <option value="c">Mark</option>
</select>

Upvotes: 2

Related Questions