Remove newlines from textarea

[Total: 0    Average: 0/5]

This example removes newlines from a textarea on a click of a button.

Body Code:

<form name=exf1>
<textarea name=ta rows=5 cols=10 >
a
b
c
d
e
f
</textarea><BR>
<input type=button value="Remove Newlines" onclick=rn()>
</textarea>
</form>
<script>
function rn() {
  var _s = document.exf1.ta.value;
  var _t = "";
  for (_i=0;_i<_s.length;_i++) {
    if (_s.charCodeAt(_i) != 13 &&
	    _s.charCodeAt(_i) != 10)
	  _t += _s.charAt(_i);
  }
  document.exf1.ta.value=_t;
}
</script>

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *