Angeline
Angeline

Reputation: 2379

how to get the multiple values of a select box?

I have a multiple select box which appears when I click the link 'Share'. Now I want to get the values of the options selected. How do I do that? is it $('#userList').val()? And also I have a doubt whether I could wrote the value property of option like this: ?

   $(document).ready(function(){
    var flag=0;
    $('#share_form').hide();

            $('.Share').click(function(){
        if(flag==1){
            $('#share_form').hide('fast');
            flag=0;
        }
        else{
            $('#share_form').show('slow');
        flag=1;
            return false;
        }

     });

      });//ready

    <a href="#" class="Share">Share</a>
    <div id="share_form">
    <p>Select the users with whom you want to share the Form</p>

    <select id="userList" name="userList" multiple>
        <?php foreach($users as $user){  ?>
            <option value="$user['User']['name']"><?php echo $user['User']['name'];?></option>
        <?php }?>
    </select> 
    </div>

Upvotes: 0

Views: 2798

Answers (1)

Sampson
Sampson

Reputation: 268462

Selectors/selected

$("#userList option:selected").each(function(){
  alert($(this).text());
});

Upvotes: 3

Related Questions