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

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

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *