beachlover said:
Hey Martin:
thanks for your quick response.. however, could you pls diagnose what
is wrong with the following code and where:
it shows an error:
----------------------------------------------------------------------
Line: 25
Char: 1
Error:"Object doesnt support this property or method"
Code: 0
----------------------------------------------------------------------
Which points to exactly where the error is (see below).
[...]
<Script language = "JavaScript">
The language attribute is depreciated, type is required:
<script type="text/javascript">
You're probably better off keeping tags either all uppercase or all
lowercase, it's not really important for HTML but when (if?) a
transition to XHTML takes place it may be significant.
[...]
myArray2=new Array ("This is first string. This is second string.")
document.write("<pre>")
document.write("myArray2.toLowerCase()\t\t:")
document.write(myArray2.toLowerCase()+"<BR>")
You can get away with omitting semi-colons ';' in JavaScript but it
isn't a good idea. Much better to put them all in where they are
supposed to be.
This above is line 25. You are trying to call the toLowerCase method of
the array 'myArray2'. But arrays don't have a toLowerCase method,
strings do. You have two choices:
1. Declare myArray2 as a string:
myArray2 = "This is first string. This is second string.";
in which case it should perhaps be called 'aString' to avoid confusion
(I really loath anything called 'my' whatever).
2. Use a reference to an item within myArray that is a string:
document.write( myArray2[0].toLowerCase() + "<BR>" )
But I can't see the point of using an array when a simple string will do
the job.
You can also remove a heap of code by using only one document.write
statement for each block of stuff:
<script type="text/javascript">
myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0];
document.write(
"<pre>",
"myArray.toString()\t:\t\t",
myArray.toString()+"<BR>",
"myArray.join('|')\t:\t\t",
myArray.join("|")+"<BR>",
"myArray.reverse()\t:\t\t",
myArray.reverse()+"<BR>",
"myArray.sort()\t\t:\t\t",
myArray.sort()+"<BR>",
"</pre>" + "<hr>"
);
aString = "This is first string. This is second string."
document.write(
"<pre>",
"aString.toLowerCase()\t\t:",
aString.toLowerCase()+"<BR>",
"aString.toUpperCase()\t\t:",
aString.toUpperCase()+"<BR>",
"aString.substring(8)\t\t:",
aString.substring(8)+"<BR>",
"aString.substring(4,12)\t\t:",
aString.substring(4,12)+"<BR>",
"aString.split('is')\t\t:",
aString.split('is')+"<BR>",
"aString.charAt(9)\t\t:",
aString.charAt(9)+"<BR>",
"aString.charCodeAt(2)\t\t:",
aString.charCodeAt(2)+"<BR>",
"aString.indexOf('second')\t:",
aString.indexOf('second')+"<BR>",
"</pre>"
);
</script>
[...]