Reading option values in select

Posted by user281180 on Stack Overflow See other posts from Stack Overflow or by user281180
Published on 2010-03-25T06:15:07Z Indexed on 2010/03/25 6:23 UTC
Read the original article Hit count: 352

Filed under:
|

I have select values as follows:

<select id="SelectBox" multiple="multiple">

            <% foreach (var item in Model.Name)
            { %>
                <option value="<%= item.Value %>"><%=item.Text%></option>
            <% } 
            %>

            </select>

I have a function in jquery that will have to read both the text and value. I need to have the values in array so that I can display them in a table with a column Id and another column text. My problem is that Im not able to retrieve each and every value separately. Im having the text in one line, test1test2test3.

function read() {
            $("#SelectBox").each(function() {
                var value = $(this).val();
                var text = $(this).text();
                alert(value);alert(text);

            });
        }

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about mvc