Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Problema select

  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2001
    residenza
    Milano
    Messaggi
    217

    Problema select

    Ragazzi,
    Ho un modulo con una serie di bottoni che una volta cliccati chiamano la funzione InsertHtml(TagNum)

    Ecco l'esempio:<input type="button" width="130" style="width: 130" value="Grassetto" name="B1" onclick="InsertHtml('1');">

    Vorrei fare in modo che la stessa cosa accada anche con le select tipo questa:

    <select name="fontselect">
    <option value="0">FONT</option>
    <option value="arial">Arial</option>
    <option value="times new roman">Times</option>
    <option value="courier new">Courier</option>
    <option value="century gothic">Century</option>
    </select>

    Io ho pensato di fare cosi ma non funziona ....
    codice:
    function InsertHtml(TagNum) {
      var HtmTag1     = "";
      var HtmTag2     = "";
    
      if ( LastFocus != "" ) {
        SavePreviousTextInput();
        switch ( TagNum ) {
        case "1" :
          HtmTag1 = "";
          HtmTag2 = "";
          break;
        case "2" :
          HtmTag1 = "";
          HtmTag2 = "";
          break;
        case "3" :
          HtmTag1 = "
    
     ";
          HtmTag2 = "</p>";
          break;
        case "4" :
          HtmTag1 = "<ul>\n[*]";
          HtmTag2 = "\n[/list]";
          break;
        case "5" :
          HtmTag1 = "
    ";
          HtmTag2 = "";
          break;
        case "6" :
          HtmTag1 = "<centerpar>";
          HtmTag2 = "</centerpar>";
          break;
        case "7" :
          HtmTag1 = "<justifiedpar>";
          HtmTag2 = "</justifiedpar>";
          break;
        case "8" :
          HtmTag1 = "<rightpar>";
          HtmTag2 = "</rightpar>";
          break;
        case "9" :
          HtmTag1 = "<wwwlink>";
          HtmTag2 = "</wwwlink>";
          break;
        case "10" :
          HtmTag1 = "<mailto>";
          HtmTag2 = "</mailto>";
          break;
    case "11" :
    HtmTag1 = "<font='+document.bottoni.fontselect.options[document.bottoni.fontselct.selectedIndex].value;  +'>";
    HtmTag2 = "</font>";
    break;    
        default :
          HtmTag = "";
        }
    Praticamente dovrebbe venire una cosa del genere:

    HtmTag1 = "<font=Times New Roman>";
    HtmTag2 = "</font>";

  2. #2
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    Non e' che hai solo dimenticato qualche apice (e messo un ; in piu')?

    HtmTag1 = "<font='"+document.bottoni.fontselect.options[document.bottoni.fontselct.selectedIndex].value +"'>";

    ciao
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2001
    residenza
    Milano
    Messaggi
    217
    Visto che sei in gamba potresti darmi una mano a fare in modo che oltre ai bottoni possa utilizzare anche le select .........

    Il form in oggetto lo trovi qui:http://www.immobilieweb.com/modofferta.htm

    Praticamente se selezioni il testo e clicchi i bottoni vedrai inserirsi i tag associati al bottone; con le select dovrebbe capitare la medesima cosa.

    Una sorta dello SMITZ ....più semplificato.

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    HtmTag1 = "<font='+document.bottoni.fontselect.options[document.bottoni.fontselect.selectedIndex].value;  +'>";
    Roby

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2001
    residenza
    Milano
    Messaggi
    217
    Ragazzi,
    Sto creando un form con più textarea ed una serie di bottoni cliccando sui quali si può personalizzare il testo con: Grassetto, Corsivi ecc .....
    Il problema nasce dal tag 9 in quanto:
    per quel che concerne il tag 9 vorrei che fosse concesso all'utente la possibilità del doppio inserimento

    codice:
    LINK (normale) quindi 
    LINK + DESC qunidi  [/url]"wwww.miosito.com"]desc[/url]
    e poi nei tag successiv dal 10 in poi no so come manipolare il codice per fare in modo che vengano inseriti.

    codice:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    
    var FormNumber          = 1;
    var LastFocus           = "";
    var LastDirection       = 1;
    var InsertionCounter    = 0;
    var MaxInsertionCounter = 0;
    var InsertionHistory    = new Array();
    var FocusHistory        = new Array();
    var InitialState        = new Array();
    
    function Undo() {
      if ( LastFocus != "" ) {
        if ( LastDirection == 1 ) SavePreviousTextInput();
        LastDirection = -1;
        if ( InsertionCounter > 0 ) {
          InsertionCounter = InsertionCounter - 2;
          document.forms[FormNumber].elements[FocusHistory[InsertionCounter]].value = InsertionHistory[InsertionCounter];
        }
      }
    }
    function Redo() {
      LastDirection = 1;
      if ( InsertionCounter < MaxInsertionCounter ) {
        InsertionCounter = InsertionCounter + 2;
        document.forms[FormNumber].elements[FocusHistory[InsertionCounter-1]].value = InsertionHistory[InsertionCounter-1];
      }
    }
    function SavePreviousTextInput() {
        lastSavedFocusIndex = -1;
        for ( I = 0; I < InsertionCounter; I++ ) {
    	if ( FocusHistory[I] == LastFocus ) lastSavedFocusIndex = I;
        }
        if ( lastSavedFocusIndex == -1 ) {
    	previousState = InitialState[LastFocus];
        } else {
    	previousState = InsertionHistory[lastSavedFocusIndex];
        }
        if ( previousState != document.forms[FormNumber].elements[LastFocus].value ) {
    	InsertionHistory[InsertionCounter] = previousState;
    	FocusHistory[InsertionCounter] = LastFocus;
    	InsertionCounter = InsertionCounter + 1;
    	InsertionHistory[InsertionCounter] = document.forms[FormNumber].elements[LastFocus].value;
    	FocusHistory[InsertionCounter] = LastFocus;
    	InsertionCounter = InsertionCounter + 1;
    	MaxInsertionCounter = InsertionCounter;
        }
    }
    
    function GetLastEntry(ObjectName) {
        if ( !InitialState[ObjectName] ) {
    	// this field has never been focused before, save initial state
    	InitialState[ObjectName] = document.forms[FormNumber].elements[ObjectName].value;
        } 
        if ( LastFocus != "" ) SavePreviousTextInput();
        LastFocus = ObjectName;
    }
    
    function InsertHtml(TagNum) {
    
      var HtmTag1     = "";
      var HtmTag2     = ""; 
      if ( LastFocus != "" ) {
        SavePreviousTextInput();
        switch ( TagNum ) {
        case "1" :
          HtmTag1 = "";
          HtmTag2 = "";
          break;
        case "2" :
          HtmTag1 = "";
          HtmTag2 = "";
          break;
        case "3" :
          HtmTag1 = "
    
     ";
          HtmTag2 = "</p>";
          break;
        case "4" :
          HtmTag1 = "<ul>\n[*]";
          HtmTag2 = "\n[/list]";
          break;
        case "5" :
          HtmTag1 = "
    ";
          HtmTag2 = "";
          break;
        case "6" :
          HtmTag1 = "<centerpar>";
          HtmTag2 = "</centerpar>";
          break;
        case "7" :
          HtmTag1 = "<justifiedpar>";
          HtmTag2 = "</justifiedpar>";
          break;
        case "8" :
          HtmTag1 = "<rightpar>";
          HtmTag2 = "</rightpar>";
          break;
        case "9" :
         HtmTag1 = "<wwwlink>";
        HtmTag2 = "</wwwlink>";
          break;
    
       case "10" :
        HtmTag1 = "<mailto>";
        HtmTag2 = "</mailto>";
          break;
         case "11" :   
         HtmTag1 ="<font="+document.bottoni.fontselect.options[document.bottoni.fontselect.selectedIndex].value+">";
         HtmTag2 = "</font>";
          break;          
    
       default :
          HtmTag = "";
        } 
        
        LastDirection = 1;
        InsertionHistory[InsertionCounter] = document.forms[FormNumber].elements[LastFocus].value;
        FocusHistory[InsertionCounter] = LastFocus;
        InsertionCounter = InsertionCounter + 1;
    
        if ( document.selection && document.selection.createRange ) {
          range = document.selection.createRange();
          if ( range.text != "" ) {
            if ( TagNum < 9 ) {
              if ( TagNum == 4 ) {
                SelText = range.text;
                var Ergebnis = SelText.match(/\n/);
                if ( Ergebnis != null ) {
                  var NewSelText = SelText.replace(/\n/g,"\n[*]");
                  HtmTag1 = "<ul>\n[*]";
                  HtmTag2 = "\n[/list]\n";
                  SelText = HtmTag1 + NewSelText + HtmTag2;
                }
              } else {
                SelText = HtmTag1 + range.text + HtmTag2;
              }
            } else {
    	  if (TagNum == 9) {
    	    SelText = HtmTag1 + range.text + HtmTag2 ;
    	  }
            }
            range.text = SelText;
          } else {
            if ( TagNum < 9 ) {
              document.forms[FormNumber].elements[LastFocus].value = HtmTag1 + document.forms[FormNumber].elements[LastFocus].value + HtmTag2;
            } else {
              document.forms[FormNumber].elements[LastFocus].value = document.forms[FormNumber].elements[LastFocus].value + HtmTag1 + "http://www.ndtanimtion.com" + HtmTag2 + "<wwwdesc>Descrizione del link</wwwdesc>";
            }
          }
        } else {
          if ( TagNum < 9 ) {
            document.forms[FormNumber].elements[LastFocus].value = HtmTag1 + document.forms[FormNumber].elements[LastFocus].value + HtmTag2;
          } else {
            document.forms[FormNumber].elements[LastFocus].value = document.forms[FormNumber].elements[LastFocus].value + HtmTag1 + "http://www.ndtanimtion.com" + HtmTag2 + "<wwwdesc>Descrizione del link</wwwdesc>";
          }
        }
        InsertionHistory[InsertionCounter] = document.forms[FormNumber].elements[LastFocus].value;
        FocusHistory[InsertionCounter] = LastFocus;
        InsertionCounter = InsertionCounter + 1;
        MaxInsertionCounter = InsertionCounter;
      }
    }
    //-->
    </SCRIPT>

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 © 2026 vBulletin Solutions, Inc. All rights reserved.