Username:   Password:  

Getting the value of multiple selected options

var foo = [];  
$('#multiple :selected').each(function(i, selected){
  foo[i] = $(selected).text();
});
// to get the selected values, just use .val() - this returns a string or array
foo = $('#multiple :selected').val();  

We’re using jQuery’s “each()” method to loop through all selected options in a multiple select list. Each value or text value is read into an array for later use.

Tags

jQuery javascript input select form

Get the value of a selected option with jQuery

$('#selectList').val();

Tags

jQuery javascript input

jQuery Ajax example

$(document).ready(function() {
	$("#link").click(function() {
		$("#output").load(
						"site.php",
						{ id: 4, name: "test" },
						function() {
							alert("I was clicked");
						}
		);
	});
});

Loads page "site.php" with passed post variables "id" & "name" and posts the output to div "output", when DOM element with id "link" is clicked

Tags

jQuery Javascript Ajax

Set multiple HTML attributes with jQuery

$("#myimg").attr({
	src : "myimage.gif",
	title : "My Image",
	alt : "My Image",
	border : 0
});

Tags

jQuery Javascript