Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<html>
<head>
<script type="text/javascript">
<!--
// sort function - ascending (case-insensitive)
function sortFuncAsc(record1, record2) {
var value1 = record1.optText.toLowerCase();
var value2 = record2.optText.toLowerCase();
if (value1 > value2) return(1);
if (value1 < value2) return(-1);
return(0);
}
// sort function - descending (case-insensitive)
function sortFuncDesc(record1, record2) {
var value1 = record1.optText.toLowerCase();
var value2 = record2.optText.toLowerCase();
if (value1 > value2) return(-1);
if (value1 < value2) return(1);
return(0);
}
function sortSelect(selectToSort, ascendingOrder) {
if (arguments.length == 1) ascendingOrder = true; // default to ascending sort
// copy options into an array
var myOptions = [];
for (var loop=0; loop<selectToSort.options.length; loop++) {
myOptions[loop] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
}
// sort array
if (ascendingOrder) {
myOptions.sort(sortFuncAsc);
} else {
myOptions.sort(sortFuncDesc);
}
// copy sorted options from array back to select box
selectToSort.options.length = 0;
for (var loop=0; loop<myOptions.length; loop++) {
var optObj = document.createElement('option');
optObj.text = myOptions[loop].optText;
optObj.value = myOptions[loop].optValue;
selectToSort.options.add(optObj);
}
}
//-->
</script>
</head>
<body>
<form>
<select name="mySelect">
<option value="3">Cat</option>
<option value="4">Dog</option>
<option value="2">Fish</option>
<option value="1">Bird</option>
</select>
<br />
<input type="button" onclick="sortSelect(this.form['mySelect'], true);" value="Sort (Asc)">
<input type="button" onclick="sortSelect(this.form['mySelect'], false);" value="Sort (Desc)">
</form>
</body>
</html>