Jump to content


Photo

Tags No Textarea Js


  • Faça o login para participar
5 replies to this topic

#1 scorninpc

scorninpc

    Novato no fórum

  • Usuários
  • 6 posts
  • Sexo:Não informado

Posted 22/09/2005, 12:15

gente, to fazendo ums botões para colocar tags bbcode no textarea, mas no firefox naum funciona, só no ie

<script>
function InsertText(tag1, tag2, element_id){
     theSelection = document.selection.createRange(element_id).text;
     text.focus();
     if (theSelection == " ")
            document.createRange(element_id).text = tag1 + " " + tag2;
     else
            document.selection.createRange(element_id).text = tag1 + theSelection + tag2;
 }
</script>

<textarea name="text" rows=15 cols=45>
</textarea><BR>
<a href="javascript:InsertText('[B]', '[/B]', 'text');" style="CURSOR: default"><img src="imagens/editbold.gif" width="16" height="16" border="0"></a>&nbsp;

ai segue o codigo, creio que seja o createRange

alguem teria um code "gererico" ai :P

#2 Alex Hiroshi

Alex Hiroshi

    Super Veterano

  • Ex-Admins
  • 4923 posts
  • Sexo:Masculino
  • Localidade:São Paulo - SP

Posted 22/09/2005, 21:13

Eu tbm acho que é o createRange() e o selection...
http://forum.wmonlin...howtopic=122933
Fórum WMO - Equipe de Desenvolvimento / Banco de Dados - Ex-Administrador

#3 scorninpc

scorninpc

    Novato no fórum

  • Usuários
  • 6 posts
  • Sexo:Não informado

Posted 23/09/2005, 21:35

alex, ja tinha visto o tópico, mas naum ajudou muito

se tiver mas alguma coisa serei grato :)

#4 Alex Hiroshi

Alex Hiroshi

    Super Veterano

  • Ex-Admins
  • 4923 posts
  • Sexo:Masculino
  • Localidade:São Paulo - SP

Posted 23/09/2005, 21:54

Fale sobre os testes que vc fez, o pq não ajudou, erros?
Fórum WMO - Equipe de Desenvolvimento / Banco de Dados - Ex-Administrador

#5 scorninpc

scorninpc

    Novato no fórum

  • Usuários
  • 6 posts
  • Sexo:Não informado

Posted 24/09/2005, 13:44

achei um exemplo bem interessate e o modifiquei conforme me interessava
meu prob ja está resolvido, posto ele caso minha duvida seja de outra pessoa tb

script
<script type="text/javascript">

function countInstances(open,closed){
     var opening = document.hop.contenu.value.split(open);
     var closing = document.hop.contenu.value.split(closed);
     return opening.length + closing.length - 2;
}

function TAinsert(text1,text2,contenu){
     var ta = document.getElementById(contenu);
     if (document.selection){
        var str = document.selection.createRange().text;
        ta.focus();
        var Tam = text2.length;
        var sel = document.selection.createRange();
        if (text2 != ""){
      sel.text = text1 + sel.text + text2;
        }
        else{
            sel.text = sel.text + text1;
        }
     }
     else if (ta.selectionStart | ta.selectionStart == 0){
        if (ta.selectionEnd > ta.value.length) { ta.selectionEnd = ta.value.length;
     }
        var firstPos = ta.selectionStart;
        var secondPos = ta.selectionEnd+text1.length;
        ta.value=ta.value.slice(0,firstPos)+text1+ta.value.slice(firstPos);
        ta.value=ta.value.slice(0,secondPos)+text2+ta.value.slice(secondPos);
        ta.selectionStart = firstPos+text1.length;
        ta.selectionEnd = secondPos;
        ta.focus();
     }
     else
     { // Opera
        var sel = document.hop.contenu;

        var instances = countInstances(text1,text2);
        if (instances%2 != 0 && text2 != ""){ sel.value = sel.value + text2; }
        else{ sel.value = sel.value + text1; }
     }
  }
</script>

Chamada:
<img src="imagens/bold.gif" width="16" onclick="TAinsert('[B]', '[/B]', 'message');" height="16" border="0">&nbsp;

valeu alex vc me fez fica mais curioso sobre javascript :D

Edição feita por: scorninpc, 24/09/2005, 13:48.


#6 tekoBR

tekoBR

    Novato no fórum

  • Usuários
  • 12 posts
  • Sexo:Não informado

Posted 29/03/2007, 07:12

Em que lugar da página tem que ficar esse java script e em que lugar tem que ficar a chamada?




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq