I currently use a basic BBCode script for my projects.
The problem is, BBCode only works for the first textarea. If I include other textareas, it start bugging.
For example;
In the first textarea, if I press the B image (means BBCode bold) it writes “[b] [/b]” in both of the textareas. In the second textarea, if I press the B image (means BBCode bold) nothing happens.
Edit: I just erased wall of text in my comment and moved everything to JSFiddle. The live example is here: http://jsfiddle.net/vveaQ/4/
Let me explain you the issue. Try clicking on the B button at third row. It will write [b] [/b] on all textareas. The one above when clicked, will write [b] [/b] to second and third textareas, the one at top will write [b] [/b] to top only. (works as intended.)
I have tried several things to solve this (e.g renaming textarea ID’s) but nothing has helped. Can anyone help me about this issue?
I’ll appreciate any kind of help.
Your
bbcodefunction creates elements with equal IDs and attaches event handlers to all of them:When you have three bars, the first one will have three
clickhandlers attached to it.