When bbcode() called, the function only works in the textarea where it was called the first time.
How to get the id current item every time? Or maybe you can somehow clear the id ?
Html code:
<ul> <li class="item" id="item-21351"> <a href="javascript:void(0)" class="edit">Редактирование</a> <div class="content"> <div class="describe"></div> </div> </li> <li class="item" id="item-23512"> <a href="javascript:void(0)" class="edit">Редактирование</a> <div class="content"> <div class="describe"></div> </div> </li> <li class="item" id="item-12351""> <a href="javascript:void(0)" class="edit">Редактирование</a> <div class="content"> <div class="describe"></div> </div> </li> </ul> Clicking on edit calls the form:
<form method="post"> <div class="btn" onclick="bbcode('redit','[tag]','[/tag]')" >[tag]</div> <textarea name="redit" class="redit" id="redit"></textarea> </form> bbcode replaces selected text
<script> function bbcode(elementID, openTag, closeTag){ var tarea = document.getElementById( elementID ); var val = tarea.value; var s = tarea.selectionStart; var e = tarea.selectionEnd; tarea.value = val.substring( 0, s ) + openTag + val.substring( s, e ) + closeTag + val.substring( e, val.length ); } </script>
textareawith the same id? It won't work like that - sercxjo