This is absolutely the darnedest thing I have ever seen, and when I think I've seen it all, this takes the cake. OK, I copied an example out of a Beginning JavaScript book - and I mean word for word. The script is supposed to reverse lines in a text area. I am posting two versions of this script: the one I copied out of the book, and a downloaded copy of the same script. Here's the kicker: the downloaded copy works absolutely beautifully, but mine doesn't work at all - and the code is IDENTICAL! Oh, and btw, the browser found no errors in my code. I am posting both of them, and you tell me if there is anything different. Here's mine:
Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript>
function splitAndReverseText(textAreaControl)
{
var textToSplit = textAreaControl.value;
var textArray = textToSplit.split('\r\n');
var numberOfParts = 0;
numberOfParts = textArray.length;
var reversedString = "";
var indexCount;
for (indexCount = numberOfParts - 1; indexCount >= 0; indexCount--)
{
reversedString = reversedString + textArray[indexCount];
if (indexCount > 0)
{
reversedString = reversedString + "\r\n";
}
}
textAreaControl.value = reversedString;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=form1>
<TEXTAREA ROWS=20 COLS=40 NAME=textarea1 WRAP=soft>Line 1
Line 2
Line 3
Line 4</TEXTAREA>
<BR>
<INPUT TYPE="button" VALUE="Reverse Line Order" NAME=buttonSplit onclick="splitAndReverseText(document.form1.textarea1)">
</FORM>
</BODY>
</HTML>
Now the downloaded copy:
Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript>
function splitAndReverseText(textAreaControl)
{
var textToSplit = textAreaControl.value;
var textArray = textToSplit.split('\r\n');
var numberOfParts = 0;
numberOfParts = textArray.length;
var reversedString = "";
var indexCount;
for (indexCount = numberOfParts - 1; indexCount >= 0; indexCount--)
{
reversedString = reversedString + textArray[indexCount];
if (indexCount > 0)
{
reversedString = reversedString + "\r\n";
}
}
textAreaControl.value = reversedString;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=form1>
<TEXTAREA ROWS=20 COLS=40 NAME=textarea1 WRAP=soft>Line 1
Line 2
Line 3
Line 4</TEXTAREA>
<BR>
<INPUT TYPE="button" VALUE="Reverse Line Order" NAME=buttonSplit
onclick="splitAndReverseText(document.form1.textarea1)">
</FORM>
</BODY>
</HTML>
\r (I think) is a Mac OS 9 and earlier end of line.
When the line ending of the content in the textarea field is different than what the JavaScript is looking for, then the lines won't be split. Without them being split, they can't be reordered.
Try saving both versions with the same line endings. Or, alternatively, replace \r\n with \n on the two lines and see if it will work.
Will
__________________
Numerology API for apps - Facebook, iPad, mobile phones. No charge to use API. [info]
That still doesn't explain why the two scripts are identical but one fails. I know this sounds absurd, but it seems like the only difference is the difference in authors, and mine fails because I'm the wrong author, or it hates me, or whatever. Did anyone see any difference b/w the two scripts?
That still doesn't explain why the two scripts are identical but one fails. I know this sounds absurd, but it seems like the only difference is the difference in authors, and mine fails because I'm the wrong author, or it hates me, or whatever. Did anyone see any difference b/w the two scripts?
I copied and pasted both of your posts and neither one worked.
That still doesn't explain why the two scripts are identical but one fails. I know this sounds absurd, but it seems like the only difference is the difference in authors, and mine fails because I'm the wrong author, or it hates me, or whatever. Did anyone see any difference b/w the two scripts?
Actually, they're not identical. One has 845 characters and the other 864. When two files have identical visible characters, yet behave differently, the invisible characters (spaces, tabs, line endings, etc.) may be the reason for the different behavior.
Will
__________________
Numerology API for apps - Facebook, iPad, mobile phones. No charge to use API. [info]