DeanWhitehouse Posted July 18, 2008 Share Posted July 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 18, 2008 Author Share Posted July 18, 2008 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.