views:

40

answers:

0

I have a user interface where I'm toggling between HTML markup view and rendered view. An HTML Editor.

Using Javascript I have set that if anyone types any word and presses enter and then types another word then it should render as two lines. In HTML view this is an inserted <BR> tag as per my expectation.

But when we insert a table with the editir then in the render view it adds the <BR> tag after every table tag.

i.e. I want it to output this:

<TABLE border=1 cellPadding=10 fontname="Arial">
<TBODY>
<TR>
<TD><FONT size=+0>&nbsp;</FONT></TD>
<TD><FONT size=+0>&nbsp;</FONT></TD>
<TD><FONT size=+0>&nbsp;</FONT></TD></TR>
<TR>
<TD><FONT size=+0>&nbsp;</FONT></TD>
<TD><FONT size=+0>&nbsp;</FONT></TD>
<TD><FONT size=+0>&nbsp;</FONT></TD></TR>
<TR>
<TD><FONT size=+0>&nbsp;</FONT></TD>
<TD><FONT size=+0>&nbsp;</FONT></TD>
<TD><FONT size=+0>&nbsp;</FONT></TD></TR></TBODY></TABLE>

But it outputs like this:

<TABLE border=1 cellPadding=10 fontname="Arial"><br>
<TBODY><br>
<TR><br>
<TD><FONT size=+0>&nbsp;</FONT></TD><br>
<TD><FONT size=+0>&nbsp;</FONT></TD><br>
<TD><FONT size=+0>&nbsp;</FONT></TD></TR><br>
<TR><br>
<TD><FONT size=+0>&nbsp;</FONT></TD><br>
<TD><FONT size=+0>&nbsp;</FONT></TD><br>
<TD><FONT size=+0>&nbsp;</FONT></TD></TR><br>
<TR><br>
<TD><FONT size=+0>&nbsp;</FONT></TD><br>
<TD><FONT size=+0>&nbsp;</FONT></TD><br>
<TD><FONT size=+0>&nbsp;</FONT></TD></TR></TBODY></TABLE>

I'm using the function below:

document.getElementById(Ctrid).value = document.getElementById(Ctrid).value.replace(/<br>/gi, "\n")

var strText = document.getElementById(Ctrid).value.replace(/\r/gi, "<br>");

Can anybody tell me how can I avoid this problem, or provide a better solution?