var numnames=0;     initialize the counter and the array
var names = new Array();
function SortNames() a new function called “SortNames” is created

{thename=document.theform.newname.value;      Gets “thename” from the text field

names[numnames]=thename;         Add the name to the array

numnames++;        Increment the counter

names.sort();        Sort the array
document.theform.sorted.value=names.join(“\n”);}

Advertisement