This will center the first line of your default text. You should be able to figure out how to do more lines if you want.
<html>
<body onload="centerIt()">
<script language="javascript">
function centerIt()
{
var box = document.getElementById('txtBox');
var defaultString = "Hello World";
//determine how many spaces move over to center
var leftPos = (box.cols - defaultString.length)/2;
var newString = "";
//add that mant spaces to the beginning of the new string
for (var i=0; i < leftPos; i++)
newString += " ";
//If you don't put a space after the string, strings containing
//no strings will not be printed (don't know why)
newString += defaultString + " ";
box.innerHTML = newString;
}
</script>
<form method="POST">
<p><textarea rows="2" name="txtBox" id="txtBox" cols="20"></textarea></p>
</form>
</body>
</html>
If you want all text in the text area to be centered use:
<textarea rows="2" name="txtBox" id="txtBox" cols="40" style="text-align:center"></textarea>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.