Pages

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");


Show Dropdown Item by selected Text



$("#ddlname option:contains(" + $("#txtname").val() + ")").attr('selected', true);


Add Item



$("<option value=\"3\">Reject</option>").appendTo("#YourItem");


Remove Item

Remove an item from drop-down list using value attribute 

Syntax:

$("#drip_ID option[value='Value_To_Remove']").remove();

Example : 

$("#ddlStaff option[value='" + $("#hidUserId").val() +"']").remove();

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>

No comments:

Post a Comment