Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    Iserire testo in textarea da bottone

    Ciao

    Ho un form che permette di inserire un testo in una textarea da un bottone di input ( tipo come inserire i codici delle faccine in questo form) ed uso una cosa del genere :

    codice:
    <form name="ciao">
    <input type="button" name="bottone" value="scrivi" onClick='document.ciao.testo.value+="testo da scrivere"'>
    <textarea name="testo" value="textarea" cols="32" rows="2">
    </textarea>
    </form>
    Il testo si scrive però dopo l'ultima lettere scritta ( come in questo forum ) eio invece vorrei che si scrivesse dove è puntato il muose .

    E' possibile ?

    ciao

  2. #2
    Guido Piazza
    Guest
    Ciao forse dico una bestialità,ma potresti usare l'evento paste di js...insomma quello che simula l'incolla
    Non sò se fà l'effetto desiderato,quindi non posso far altro che consigliarti una ricerca nel forum apposito (scripting)


    Bye

  3. #3
    Grazie del consiglio ma non conosco questo effetto di js che tu indichi

  4. #4
    Reale_Augello
    Guest

    Funziona...


  5. #5
    Grazie di aver risposto !

    Lo ho provato ma mi da errore !

  6. #6
    Reale_Augello
    Guest

    ...

    Originariamente inviato da piero06
    Grazie di aver risposto !

    Lo ho provato ma mi da errore !
    Non saprei cosa dirti, dato che non l'ho provato.

  7. #7
    Guido Piazza
    Guest
    codice:
    <html>
    <head>
    <script language=javascript>
    <!--
    
    function markSelection ( txtObj ) {
     if ( txtObj.createTextRange ) {
       txtObj.caretPos = document.selection.createRange().duplicate();
       isSelected = true;
     }
    }
    
    function insertTag ( txtName, tag, enclose ) {
     var closeTag = tag;
     if ( enclose ) {
       var attribSplit = tag.indexOf ( ' ' );
       if ( tag.indexOf ( ' ' ) > -1 )
         closeTag = tag.substring ( 0, attribSplit );
     }
     if ( isSelected ) {
       var txtObj = eval ( "document.forms[0]." + txtName );
       if (txtObj.createTextRange && txtObj.caretPos) {
         var caretPos = txtObj.caretPos;
         caretPos.text = ( ( enclose ) ? "<"+tag+">"+caretPos.text+"</"+closeTag+">" : "<"+tag+">"+caretPos.text );
         markSelection ( txtObj );
         if ( txtObj.caretPos.text=='' ) {
           isSelected=false;
        txtObj.focus();
         }
       }
     } else {
       // placeholder for loss of focus handler
     }
    }
    
    //-->
    </script>
    </head>
    <body>
    <form>
    <textarea name="tsttxt" ONSELECT="markSelection(this);" ONCLICK="markSelection(this);" ONKEYUP="markSelection(this);">
    </textarea>
    <input type="button" value="BOLD" onClick="insertTag ( 'tsttxt', 'b', true )"> 
    <input type="button" value="PARAGRAPH" onClick="insertTag ( 'tsttxt', 'p', false )">
    </form> 
    </body>
    </html>
    Prova ora,dovrebbe andare


    Bye

  8. #8
    grazie 1000 !!!!

    :mavieni: :mavieni:

    funge !!!!

    grazie !

  9. #9
    Guido Piazza
    Guest
    Di nulla


    Bye

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.