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

    TAG tramite bottoni di un form

    bel titolo!

    come faccio a creare dei tasti in un form che mettono 2 valori diversi in una textarea esempio

    tasto IMG prima pressione scrive nella text [IMG]e sul pulsante esce un'asterisco e alla seconda pressione scrive [/IMG] e l'asterisco scompare
    COME FACCIO???
    Modalità curioso ON...attendere riavvio del sistema in corso...

    Errore nessuna tastiera trovata premere un tasto per continuare...

  2. #2
    è un po lunghetto... ma funziona:

    <script>
    <!--
    // Startup variables
    var imageTag = false;
    var theSelection = false;

    // Check for Browser & Platform for PC & IE specific bits
    var clientPC = navigator.userAgent.toLowerCase(); // Get client info
    var clientVer = parseInt(navigator.appVersion); // Get browser version

    var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
    var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
    && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
    && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
    var is_moz = 0;

    var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
    var is_mac = (clientPC.indexOf("mac")!=-1);


    // Define the bbCode tags
    bbcode = new Array();
    bbtags = new Array('[img]','[/img]','','','','','
    ','
    ','
    codice:
    ','
    ','
    • ','
    ','
    1. ','
    ','','','','');
    imageTag = false;

    // Shows the help messages in the helpline window
    function helpline(help) {
    document.FormPost.helpbox.value = eval(help + "_help");
    }


    // Replacement for arrayname.length property
    function getarraysize(thearray) {
    for (i = 0; i < thearray.length; i++) {
    if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
    return i;
    }
    return thearray.length;
    }

    // Replacement for arrayname.push(value) not implemented in IE until version 5.5
    // Appends element to the array
    function arraypush(thearray,value) {
    thearray[ getarraysize(thearray) ] = value;
    }

    // Replacement for arrayname.pop() not implemented in IE until version 5.5
    // Removes and returns the last element of an array
    function arraypop(thearray) {
    thearraysize = getarraysize(thearray);
    retval = thearray[thearraysize - 1];
    delete thearray[thearraysize - 1];
    return retval;
    }


    function bbstyle(bbnumber) {
    var txtarea = document.FormPost.Post;

    txtarea.focus();
    donotinsert = false;
    theSelection = false;
    bblast = 0;

    if (bbnumber == -1) { // Close all open tags & default button names
    while (bbcode[0]) {
    butnumber = arraypop(bbcode) - 1;
    txtarea.value += bbtags[butnumber + 1];
    buttext = eval('document.FormPost.addbbcode' + butnumber + '.value');
    eval('document.FormPost.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
    }
    imageTag = false; // All tags are closed including image tags
    txtarea.focus();
    return;
    }

    if ((clientVer >= 4) && is_ie && is_win)
    {
    theSelection = document.selection.createRange().text; // Get text selection

    if (theSelection) {
    // Add tags around selection
    document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
    txtarea.focus();
    theSelection = '';
    return;
    }
    }
    else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
    {
    mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
    return;
    }

    // Find last occurance of an open tag the same as the one just clicked
    for (i = 0; i < bbcode.length; i++) {
    if (bbcode[i] == bbnumber+1) {
    bblast = i;
    donotinsert = true;
    }
    }

    if (donotinsert) { // Close all open tags up to the one just clicked & default button names
    while (bbcode[bblast]) {
    butnumber = arraypop(bbcode) - 1;
    txtarea.value += bbtags[butnumber + 1];
    buttext = eval('document.FormPost.addbbcode' + butnumber + '.value');
    eval('document.FormPost.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
    imageTag = false;
    }
    txtarea.focus();
    return;
    } else { // Open tags

    if (imageTag && (bbnumber != 14)) { // Close image tag before adding another
    txtarea.value += bbtags[15];
    lastValue = arraypop(bbcode) - 1; // Remove the close image tag from the list
    document.FormPost.addbbcode14.value = "Img"; // Return button back to normal state
    imageTag = false;
    }

    // Open tag
    txtarea.value += bbtags[bbnumber];
    if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
    arraypush(bbcode,bbnumber+1);
    eval('document.FormPost.addbbcode'+bbnumber+'.valu e += "*"');
    txtarea.focus();
    return;
    }
    storeCaret(txtarea);
    }
    -->
    </script>

    e poi:

    <form name="FormPost" id="FormPost" method="post" action="pagina.php">
    <input class="button" onClick="bbstyle(0)" type="button" value=" IMG ">

    </form>

  3. #3
    purtroppo alcuni caratteri del codice vengono qui interpretati come fossero BBcode...

    e quindi non va bene.. come possiamo fare?
    ok ti creo un txt e te lo linko:

    ApriChiudiBBcode.zip

  4. #4
    lol grazie 1000000000000000000000000000
    Modalità curioso ON...attendere riavvio del sistema in corso...

    Errore nessuna tastiera trovata premere un tasto per continuare...

  5. #5
    hai visto? ti funziona?

    fammi sapere perchè poi lo dovrò togliere dal server

    ciao

  6. #6
    funziona bene!
    tnx

    devo copiarlo e incollarlo e modificarlo tutto per mettere altri tag?
    o basta modificare dei pezzetti?
    Modalità curioso ON...attendere riavvio del sistema in corso...

    Errore nessuna tastiera trovata premere un tasto per continuare...

  7. #7
    cioè se devo aggiungere B U I CODE URL che devo fare?
    Modalità curioso ON...attendere riavvio del sistema in corso...

    Errore nessuna tastiera trovata premere un tasto per continuare...

  8. #8
    no, l'unica cosa da modificare è il tag
    <input>

    dove cambierai value e l'argomento relativo di bbstyle().

    ad esempio per inserire nella textarea e al posto di 0 metterai 2

    onClick="bbstyle(0)"
    onClick="bbstyle(2)"

    rispettando l'ordine degli elementi dell'array alla righa 26 del txt

    ti consiglio di riscaricare ora lo zip tramite il link sopra perchè ho apportato alcune piccole modifiche.

    fai un po di prove

  9. #9
    ok ho kapito e ho scaricato TNX!
    Modalità curioso ON...attendere riavvio del sistema in corso...

    Errore nessuna tastiera trovata premere un tasto per continuare...

  10. #10
    posso salvarlo in un file js solo lo script e includerlo nella pagina con il form?
    Modalità curioso ON...attendere riavvio del sistema in corso...

    Errore nessuna tastiera trovata premere un tasto per continuare...

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.