How to call single click event on click multiple button and select value in dropdown according to click button using JQuery

Total Post:341

Points:2389
 1226  View(s)
Ratings:
Rate this:
call single click event and change value of dropdown list according to clicked button usin jquery
  1. Post:194

    Points:1396
    Re: How to call single click event on click multiple button and select value in dropdown according to click button using JQuery

    Hi ankit i'm try to solve your problem


    here is my html code

    <div class="container">
        <div class="row">
            <br /><br />
            <div class="col-md-1">
                <input type="button" value="Allahabad" class="selectcity btn btn-info" id="0"/>
            </div>
            <div class="col-md-1">
                <input type="button" value="Lucknow" class="selectcity btn btn-info" id="1"/>
            </div>
            <div class="col-md-1">
                <input type="button" value="Kanpur" class="selectcity btn btn-info" id="2"/>
            </div>
            <div class="col-md-1">
                <input type="button" value="Delhi" class="selectcity btn btn-info" id="3"/>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4" ><br /><br />
                <select id="ddl-jobcategory" style="width:100%;height:35px;">
                    <option>Allahabad</option>
                    <option>Lucknow</option>
                    <option>Kanpur</option>
                    <option>Delhi</option>
                </select>
            </div>
        </div>
    </div>

    and here is my jquery code

    <script>
        $(document).ready(function () {
            $('.selectcity').click(function () {
                var index = $(this).attr("id");
                $('#ddl-jobcategory').prop("selectedIndex", index);
            });
        });
    </script>

      Modified On Apr-05-2018 06:17:44 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!