JQuery select handling

A few snippets for when it comes to handle selectboxes:

//find an option by value
var foundOption = $("#ddlPhoneCode option[value='AS']");

//get selected option 
var foundOption = $("#ddlPhoneCode").val();

//remove an option from the control
$("#ddlPhoneCode option[value='AS']").remove();

//get values from multi-select 
var foundOptions = [];
$('#ddlPhoneCode:selected').each(function(i, selected){
foundOptions[i] = $(selected).text();
});

//select an option into the select
$('#ddlPhoneCode')val('AS')

//intercept change event of the selectbox
$("#ddlPhoneCode").change(function() { alert('hello')});
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s