Saturday, 2 December 2017

Jquery Drop Down Menu Operation

Jquery Drop Down Menu Operation

Reset Drop Down List :

Syntax : 

  $('Your drop Down ID').prop('selectedIndex', 0);

E.g.

  $('#ddlServiceName').prop('selectedIndex', 0);


Select data using value attribute

Syntax :
$("#DropDownID option[value=Option Value]").text();

E.g.

$("#drpPrice option[value=1]").text();


Get Selected text


$("#id option:selected").text()


Show Dropdown Item by selected value


$("#ListBoxName").val("selectValue");


Copy all Element of drop down list into other drop down


<script>
        function Copyddl()
        {
            var x = document.getElementById("ddl1").options.length;
            var h = "";
            for (i = 0; i < x; i++)
                h +="<option>"+ document.getElementById("ddl1").options.item(i).text+"</option>";
            $("#ddl2").html(h);
        }

    </script>
<select id="ddl1">
        <option>2000</option>
        <option>2001</option>
        <option>2002</option>
        <option>2003</option>
        <option>2004</option>
    </select>
    <input type="button" value="Click" onclick="Copyddl()" />
   
    <select id="ddl2">
      

    </select>