PDA

View Full Version : Keep formatting?


Techno
04-21-2006, 11:24 AM
Hi.

I have a small client side script which simply, when you click on a button, it appends text to a textbox on the page.

however I want to be able to keep the formatting the way it is without having it to reformat it in its own way.

for example, if i have several blank lines (enter key pressed) in the textbox, as soon as you hit the button to append some text, it will reformat it, to make the line in one big long sentence instead of keeping its formatting.

hope it makes sense:



<script type="text/javascript">
function DoAppendText(theText)
{
theTextbox = document.getElementById('txtThreadMessage');
theTextbox.innerHTML += theText;
}

..
..

<input id="cmdBold" style="WIDTH: 42px; HEIGHT: 24px" onclick="DoAppendText('{b}{/b}')" type="button" value="B" name="cmdBold" runat="server">

</script>

Vege
04-21-2006, 11:49 AM
<script language="JavaScript" type="text/javascript">

function convert(text) {
var txtarea = document.post.message;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}
</script>

<a href="javascript:convert('')">B</a>
<form name='post' action='' method='post'>
<textarea cols='60' rows='10' name='message'></textarea>
</form>

Is this what your looking for?
It inserts into the textfield when you press the link

Techno
04-21-2006, 12:02 PM
perfect

thank-you :)