<textarea id="test2" cols="10" rows="8">1 2 3 4 5 6 7 8</textarea> <script type="text/javascript"> alert(document.getElementById("test2").value.replace(/[\r\n]/g, "").slice(0, 4)); </script>