topical media & game development
basic-javascript-08-ch8-examp1.htm / htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example 1</title>
<script language="JavaScript" type="text/JavaScript">
function splitAndReverseText(textAreaControl)
{
var textToSplit = textAreaControl.value;
var textArray = textToSplit.split('\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 + "\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>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.