3

see this demo from jquery ui you have to hold down the Ctrl key to make multiple selections I really like the code but I don't want to force my visitor to press ctrl key I want the code to allow multiple selections without holding ctrl key

is this possible?

1
  • Do you need the drawing box functionality? If not you could probably roll your own and I or somebody else could help with the code. Commented May 25, 2009 at 23:54

2 Answers 2

5

I asked you a questions in the comments but I'll just write up a simple selection solution so you can see what I was thinking.

So basically you can use the jquery toggle() effect to roll your own selector. When a user clicks you'll add the orange class, when he clicks again it will remove the orange class.

$(document).ready( function() {
    $('ul#selectable li').toggle( function() {
        $(this).addClass('orange'); }, function() {
        $(this).removeClass('orange'); } );
});

Then all your job is to grab all the li elements with the orange class and post them to a form or whatever your end goal is. Haven't checked this code but what your doing is asking for all the li elements within selectable that have the orange value at the end of the class attribute.

With the code below I'm creating a new array and then adding the text() value of each "orange li" into it.

var theSelections = new Array();

$('ul#selectable li[class$="orange"]').each( function(i) {
    theSelections[i] = $(this).text();
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this is what I am talking about :)
-1

Yes. However, the implementation would have to allow selected items to be deselected when clicked on a second time. You would just need to modify the code slightly to achieve this.

Do a .selectable( 'Enable' ) on all the items.

Then you will need to do a .selectable( 'toggle' ) onClick on all items.

That should do the trick.

1 Comment

From the doc: Toggles the state of selectable functionality. This method either enables or disables selecting based on the current state. If I'm reading this right your solution would basically just disable all functionality of .selectable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.