<html> <head> <title>Trim Example</title> <script type="text/javascript"> String.prototype.trim = function () { var reExtraSpace = /^\s+(.*?)\s+$/; return this.replace(reExtraSpace, "$1"); }; function showText() { var oInput1 = document.getElementById("txt1"); var oInput2 = document.getElementById("txt2"); oInput2.value = oInput1.value.trim(); } </script> </head> <body> <textarea rows="10" cols="50" id="txt1"></textarea><br /> <input type="button" value="Trim" onclick="showText()" /></p> <P>Trimmed Text:<br /> <textarea rows="10" cols="50" id="txt2"></textarea></p> </body> </html>