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();
开发者_如何学Cfunction 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:
<script type="text/javscript" language="javascript" src="sort.js">
To
<script type="text/javascript" language="javascript" src="sort.js">
?
And check if your browser can find sort.js using the debugger.
Your code looks fine, either you are using an older browser or the error is in another part of your code. Try to reduce your file to the bare minimum needed to test or use the javascript console to track down other errors.
精彩评论