Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
BRH 48
#DOTNET 34
#ASP.NET 29
jQuery 22
ASP.NET 20
.NET 20
WPF 9
jquery interview questions 9
jquery faq 8
ASP.NET4 8

Archive · View All
February 2011 10
September 2011 4
August 2011 4
July 2011 4
May 2011 4
April 2011 4
March 2011 4
October 2011 4
June 2011 4
January 2011 4

Playing with dropdownlist using jQuery - SelectedValue, SelectedText, SelectionChange, Adding, Removing Items

Aug 12 2011 1:45PM by Hima   

You might be working with ASP.NET Dropdown list or normal html dropdownlist while working with web development. In common scenarios and day to day applications we need to get value filed ( usually ID ) and text filed of the selected item in the drop down.

In this post we will examine how to get selected text or selected value from the dropdown using jQuery

Get Selected Value or Text from the Dropdownlist using jQuery

jQuery provides val() method which returns value of any element.

$("#ddlPath").val()                    – gets selected value from combo or dropdownlist

$("#ddlPath").text()                 – will give all the text values in side the dropdownlist.

$("#ddlPath option:selected").text() – gets the selected text from combo or dropdownlist

 

for ASP.NET Dropdownlist here is the code.

$('#<%= ddlPath.ClientID %>').val()        – gets selected value for the ddlPath

$('#<%= ddlPath.ClientID %>').text()       - gets text of all options $('#<%= ddlLanguage.ClientID %> option:selected').text()- gets selected text for the ddlPath .'

Append Values to the DropDown

The following is code to add a value to dropdown.

$("<option value=’34’>User Value</option>").appendTo("#ddlPath");

Selection change

Some times we need to do some dynamic operations based on value selected in selection change event. That can be done as follows.

$("#ddlPath").change(function()
{ 
    /* do something here */
});
   

To Set the selected value to ‘X’ 

$("#ddlPath").val(45);
    

Clear the DropDown

$("#ddlPath").empty(); 

To Add empty item in the first option

        $("#ddlPath").prepend("");

To Select first item as default

$("#ddlPath option:first-child").attr("selected","selected");
  

If you are looking for certain tip using dropdownlist and jQuery, please feel free to comment, I am ready to help you. Thanks for reading my post .

Tags: BRH, .NET, #DOTNET, #ASP.NET, ASP.NET, jquery dropdownlist tips,


Hima
31 · 6% · 1776
3
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • hi, how can get all value of dropdown list one by one and not all as text

    commented on Jan 16 2012 9:17AM
    kareem
    2802 · 0% · 3
  • var ddlPath = document.getElementById("ddlPath"); var dropdownValues = ""; for (var i=0;i<ddlPath.options.length;i++) { dropdownValues += ddlPath.options[i].value + ";"; } var arrDDV = dropdownValues.split(';');

    This will give you an array of the values.

    commented on Mar 2 2012 7:34PM
    Tom
    2802 · 0% · 3

Your Comment


Sign Up or Login to post a comment.

"Playing with dropdownlist using jQuery - SelectedValue, SelectedText, SelectionChange, Adding, Removing Items" rated 5 out of 5 by 3 readers
Playing with dropdownlist using jQuery - SelectedValue, SelectedText, SelectionChange, Adding, Removing Items , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]