i am trying to learn how to make a text editor.here i creat a paragraph using "para" button.and inside the paragraph there will be a quote.Every time I press 'enter' within this paragraph, a new paragraph is created, rather than a line break tag (<br>). How can I force a line break tag to be created instead of a paragraph element?also

i cant even get outside of the quote tag.though designMode is on and contenteditable is true for both paragrap and quote

<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
*{margin:0px;padding:0px;}

#idContent{
    background-color:pink;
}
div{
    border:1px solid black;
}
</style>
</head>

<body onLoad="loads();" style="position:relative;">
<iframe id="idContent" width="600" height="280" contenteditable="true" ></iframe>
<input type="button" value="para" onClick="para();">

<script>
function loads(){
    idContent.document.designMode="On";
}
function para(){

    var m=document.createElement("p");

m.setAttribute('style',"border:1px solid black;height:100px;width:500px;position:relative;background-color:white;");
m.setAttribute('designMode',"on");
m.setAttribute('contenteditable',"true");

    var t=document.createElement("q");
    t.innerHTML="quote here";
    t.setAttribute('designMode',"on");
    t.setAttribute('contenteditable',"true");
    m.appendChild(t);
    idContent.document.body.appendChild(m);

}
</script>
</body>
</html>

I do not convert it to <br>, because when user again try to edit html code, It will show <br> in the content itself.

So rather I used to display content when its not in textarea, using nl2br function.

<?php $content ="your saved data";?>

<textarea > <?php echo $content;  </textarea>

<div > <?php echo nl2br($content);  </div>
commented: nice one +14

thanks.i don't understand your php codes because i haven't learned php yet.i am concentrating on js currently.

Every time I press 'enter' within this paragraph, a new paragraph is created, rather than a line break tag (<br>). How can I force a line break tag to be created instead of a paragraph element?

Have you tried SHIFT+Enter for a new line instead of a new paragraph?

Have you tried SHIFT+Enter for a new line instead of a new paragraph?

I think you have but you are embarrased to come back and mark the thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.