lundi 6 juillet 2015

How to swap 2 @Html.DropDownListFor with Jquery/JS

I found some examples in SO. But none of them worked for me. I want to swap values of 2 @Html.DropDownListFor each other. Both DropDownList contains the same set of values except the default value to show. Below is my code.

<div class="currency_swap">
    <div class="swap_dropdown">
        @Html.DropDownListFor(m => m.SourceCurrencyname, new SelectList(ViewBag.CurrencyNames, "Currency_Code", "Currency_Code"), "---- All ----")
<div><input type="button" id="swap_up" value="&#x25B2" class="swap" /></div>
    <div class="swap_dropdown">@Html.DropDownListFor(m => m.TargetCurrencyname, new SelectList(ViewBag.CurrencyNames, "Currency_Code", "Currency_Code"), "Agency Currency")</div>

<script type="text/javascript">
$(".swap").click(function () {
    var row = $(this).closest(".currency_swap");
    var start = row.find("swap_dropdown:first select");
    var end = row.find("swap_dropdown:last select");
    var temp = start.val();

Aucun commentaire:

Enregistrer un commentaire