1

I have 4 dropdownlist in my view in asp.net mvc 5 and I want to get text and value of each select tag to send to action I use below code but every time I get the text and value of the first dropdownlist

<select id="se1" class="mySelect" onchange="f22()">
        <option value="@item.ID">1</option>
        <option value="@item.ID">2</option>
        <option value="@item.ID">3</option>
        <option value="@item.ID">4</option>
        <option value="@item.ID">5</option>
</select>
<script src="~/Scripts/jquery-1.9.1.js"></script>

<script>
    function f22() {
        var a = $("#se1 option:selected").text();
        var b = $("#se1 option:selected").val();
        alert(a)
        alert(b)
    }
</script>
1
  • can you paraphrase your description(question) ? Commented Dec 20, 2015 at 17:37

1 Answer 1

1

Pass the element to js function using this as the parameter of f22 function and then use this in js like following. Hope this will help you.

<select id="se1" class="mySelect" onchange="f22(this)">
    .........
    .........
</select>

function f22(elm) {
    var a = $(elm).find("option:selected").text();
    var b = $(elm).val();
    alert(a)
    alert(b)
}
Sign up to request clarification or add additional context in comments.

Comments

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.