Tuesday, November 22, 2011

Working with dropdownlist or combobox using jquery

More often programmers need to work with dropdownlist or combobox using jquery. We need to manipulate the dropdownlist options using jquery scripting. And it is the case that almost always we don't remember how to implement jquery selector. And for all of my readers, who are enthusiastic programmers and/or designers, and for myself, I am discussing in this post the actions with jquery to manipulate asp.net dropdownlist options.




Now append another option using jquery.
$('[id$=ddlTest]').append('');
[Why am I using the selector syntax $('[id$=ddlTest]') instead of $('#ddlTest')? We use #ControlID to select a control with specified id. $= means 'select a control whose id ends with specified value. If you are using master page, the rendered id of the dropdownlist is preceded with some text.] Now get the selected value from the dropdownlist.
var selVal=$('[id$=ddlTest]').val();
Now get the selected texct from the dropdownlist.
var selTxt=$('[id$=ddlTest] option:selected').text();
Now, select a value programmatically.
var selTxt=$('[id$=ddlTest]').val('Nepal');
And I hope you are comfortable with detecting through jquery when the use selects an item. Good luck!kick it on DotNetKicks.com

0 comments:

Post a Comment

Hope you liked this post. You can leave your message or you can put your valuable suggestions on this post here. Thanks for the sharing and cooperation!

Popular Posts

Recent Articles