I’m getting an undefined function error that for the life of me I can’t figure out. What is wrong with this script?
var numnames=0;
var names=new Array();
function SortNames(){
thename=document.theform.newname.value;
numnames++;
names.sort();
document.theform.sorted.value=names.join("\n");
}
I call the code here:
<html>
<head></head>
<body>
<script type="text/javscript" language="javascript" src="sort.js">
</script>
<h1>Sorting Array</h1>
<p>Enter two or more names in the field below, and the sorted list of names will appear in the text area<p>
<form name=theform>
Name:
<input type=text name=newname size=20>
<input type=button name=addname value=Add onclick="SortNames();">
<br/>
<h2>Sorted Names</h2>
<textarea cols=60 rows=10 name=sorted>
The sorted names will appear here
</textarea>
</form>
</body>
</html>
The error I get is SortNames is not defined.
Could you try changing:
To
?
And check if your browser can find sort.js using the debugger.