Formatting and Sorting Strings

Another typical task you might want to do is to sort a group of names. Script 8.6 combines the previous two examples and adds a sort. The end result is the list of names in last-name order, properly capitalized, and alphabetized.

Script 8.6. This script takes a bunch of names in any format and order and turns them into a neat and orderly list.
window.onload = initForms; function initForms() { for (var i=0; i< document.forms.length; i++) { document.forms[i].onsubmit = function() {return validForm();} } } function validForm() { var allTags = document.getElementsByTagName("*"); for (var i=0; i<allTags.length; i++) { validTag(allTags[i]); } return false; function validTag(thisTag) { var allClasses = thisTag.className.split(" ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.