Jump to content

[SOLVED] Insert into textarea


DeanWhitehouse

Recommended Posts

I have this code to add bbcode into a textarea

<script type="text/javascript">
function preview()
{
var current = document.getElementById("current").value;
document.getElementById("preview").innerHTML = current;
}
function insert(code)
{
var current = document.getElementById("current").value;
document.getElementById("current").innerHTML = current+code;
}
</script>
<textarea onKeyUp="preview();" id="current" rows="10" cols="50"></textarea><br/>
<span onClick="insert('[b][/b]')" style="cursor:pointer;"> Bold </span><span style="cursor:pointer;" onClick="insert('[i][/i]')"> Italic </span><span style="cursor:pointer;" onClick="insert('[s][/s]')"> Strikeout </span>
<div id="preview"></div>

 

but the code isn't added if i have entered anything into the textarea, if it is empty then it adds the code fine, but if it isn't it doesnt do anything.

Link to comment
https://forums.phpfreaks.com/topic/115485-solved-insert-into-textarea/
Share on other sites

it;s ok solved it now,

here's my code if u want it

<script type="text/javascript">
function preview()
{
var current = document.getElementById("current").value;
document.getElementById("preview").innerHTML = current;
}
function insert(code)
{
var current = document.getElementById("current").value;
document.getElementById("current").value += code;
}
</script>
<textarea id="current" onKeyUp="preview();" rows="10" cols="50"></textarea><br/>
<span onClick="insert('[b][/b]')" style="cursor:pointer;"> Bold </span><span style="cursor:pointer;" onClick="insert('[i][/i]')"> Italic </span><span style="cursor:pointer;" onClick="insert('[s][/s]')"> Strikeout </span>
<div id="preview"></div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.