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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.