All pastes #920322 Raw Edit

Mine

public html v1 · immutable
#920322 ·published 2008-02-27 10:30 UTC
rendered paste body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>	<head>		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">		<title>Untitled Document</title>		<script type="text/javascript">			var selected = [];						function doSomething() { 				var last_index = getLastIndex();				alert('Last selected option index: '+last_index);				alert('Selected array: '+selected.toSource());			}			function getLastIndex() { 				var el = document.getElementById('x');				// Loop select options				for(i=0;i<el.length;i++) { 					// Look in selected array for this option index					selected_index = selected.indexOf(i,0,true);					// Exists in selected					if(selected_index > -1) { 						// Not selected, remove						if(el.options[i].selected == false) { 							selected.splice(selected_index, 1);						}					// Doesn't exist in selected, append					} else if(el.options[i].selected && selected_index == -1) { 						selected.push(i);						return i;					}				}				// If one was removed, and at least one is still selected				if(selected.length > 0) { 					return selected[selected.length-1];				}				// Nothing is selected, or the one element in selected was just removed				return -1;			}			// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value			Array.prototype.indexOf = function(v,b,s) {				for(var i = +b || 0, l = this.length; i < l; i++ ) {					if( this[i]===v || s && this[i]==v ) { 						return i; 					}				}				// Not found				return -1;			};		</script>	</head>	<body>		<select id="x" onchange="doSomething();" multiple="multiple" size="5">			<option value="1">One</option>			<option value="2">Two</option>			<option value="3">Three</option>			<option value="4">Four</option>			<option value="5">Five</option>		</select>	</body></html>