jwimmer
jwimmer

Reputation: 209

Retrieve Selected Value of MagicSelect MultiValue

I have multiselect element just like StackOverflow does with their tags. I don't know how to write the jQuery statement that will retrieve the multiple values that were selected.

Here is what I have so far.

HTML
<input id="tagSelect" style="width:400px;" type="text"/>

Here is my Javascript

var tag = $('#tagSelect').val();

Here is the plugin that it uses http://nicolasbize.github.com/magicsuggest/

Upvotes: 2

Views: 2424

Answers (2)

Sir Geek
Sir Geek

Reputation: 51

This solution does not appear to work.

When trying to execute ms.getValue(); the following error message is logged:

TypeError: ms.getValue is not a function[Learn More]

Upvotes: 0

Gad
Gad

Reputation: 42306

There are two ways to retrieve the values with the plugin:

If the combo is included within a classic form like this:

<form method="POST" action="submit.php">
    <div id="ms"></div>
</form>

<script type="text/javascript">
    var combo = $('#ms').magicSuggest({
        data: 'a,b,c,d,e',
        name: 'choice'
    });
</script>

then the selection will be serialized in the parameter $_POST['choice'].

If you need to retrieve the values through javascript, there is a getValue() method which will return an array of values:

ms.getValue();

Upvotes: 4

Related Questions