Cod-nes Posted September 3, 2008 Share Posted September 3, 2008 How can I add text to a textarea using javascript? Example: Within this forum we may click the bold button and it adds the bbc code to the textarea. Link to comment Share on other sites More sharing options...
Jesdisciple Posted September 3, 2008 Share Posted September 3, 2008 Find what the user has highlighted and then do something like this:<html><body><textarea id="text">Maybe this works...</textarea><script type="text/javascript">function emboldenSubstring(string, start, end){ var before = string.substring(0, start); var substring = string.substring(start, end); var after = string.substring(end); return before + '[b]' + substring + '[/b]' + after;}var area = document.getElementById('text');area.value = emboldenSubstring(area.value, 6, 10);</script></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.