Hi,
I have made a BBcode editor and would like to add a function so as the user types and adds bbcode to the text area, have it show the html below it in real time as they are typing.
I beleave this would be possible using javascript?
Thanks
| SitePoint Sponsor |




Hi,
I have made a BBcode editor and would like to add a function so as the user types and adds bbcode to the text area, have it show the html below it in real time as they are typing.
I beleave this would be possible using javascript?
Thanks




Hi,
Thats basically what I am after, I cant find the javascript that is associated to it tho ...
Thanks
*edit.. there was a post above here from a member then it got deleted?

Yeah that was me. I deleted it because I realised it was rather unhelpful because using innerHTML makes that kind of thing pretty easy.
The JS can be found here: http://www.mikeindustries.com/blog/s...on-20060417.js look for ReloadTextDiv. There's also some inline JS in the HTML that it uses.
For BBCode you'd have to write a parser. Maybe it could be done with a single regular expression if only certain simple HTML is allowed. If nesting tags can happen that adds another layer of complexity.




Hi,
Great, so far I have:
I have buttons that add bbcode tags around the text. Is there away to use my existing code or do I have to write code into the javascript to convert tags?Code:<script type="text/javascript" LANGUAGE="Javascript"> function textdiv() { var NewText = document.getElementById("text").value; NewText = NewText.replace(/\n/g, '<br />'); var DivElement = document.getElementById("display"); DivElement.innerHTML = NewText; } </script>
Thanks
This might interest you, although that's markdown syntax, and not bbcode:
http://www.attacklab.net/showdown-gui.html




Hi,
Thats basically what I have. Im using BBcode tags in my text area and need then converted to html for the preview.
Im guessing you could maybe use something like
Within the javascript?PHP Code:$BBCode = array(
"[center]" => "<center>", "[/center]" => "</center>",
"[b]" => "<b>", "[/b]" => "</b>",
"[u]" => "<u>", "[/u]" => "</u>",
"[i]" => "<i>", "[/i]" => "</i>");
Thanks
As Raffles said, it's not as simple as that; If any tags are context-dependent (and some are), you need to write a parser.
Bookmarks