<html>
<head>
<script language="javascript">
function InsertBreak(e){
//check for return key=13
if (parseInt(e.keyCode)==13) {
//get textarea object
var objTxtArea;
objTxtArea=document.getElementById("test"
//insert the existing text with the <br>
objTxtArea.innerText=objTxtArea.value+"<br>";
}
Of course if the user's cursor is in the middle of the text, the "<BR>" will still get appended to the end. This script will insert a "<BR>" where the user's cursor is (IE only):
Another option would be to search and replace all line breaks with "<BR>" when the textbox loses focus.
If you're going to display the text on your web page, I'd leave the original text alone and just search and replace the line breaks with "<BR>" at the time of display. In ASP it'd look something like <%=Replace(textVariable,vbCrLf,"<BR>"%>
Yet another option would be to use <span contenteditable="true"></span> and get the innerHTML of the span when they're done.
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.