Visualizzazione dei risultati da 1 a 10 su 13

Hybrid View

  1. #1
    Utente di HTML.it L'avatar di m4rko80
    Registrato dal
    Aug 2008
    residenza
    Milano
    Messaggi
    2,655
    Mancava una graffa al codice(funziona calcola)
    codice:
    <html>
    <head>
    <script>
    var unit = 5;
    var min = 0;
    var currentValue;
    var currentText;
    
    
    
    
    window.onLoad = function(){
     currentValue = document.getElementById('valore').value || 0;
     currentText = document.getElementById('testo').value;
    }
    
    
    
    
    function calcola(event){
       
        var key = event.which || event.keyCode;  
    
    
    
    
        var inp = String.fromCharCode(key);
        if (/[a-zA-Z0-9]/.test(inp) || (key==8)){ //Tasti accettati : lettere e numeri
            currentText = document.getElementById('testo').value;
             console.log(key, document.getElementById('testo').value.length)
               var newValue = document.getElementById('testo').value.length * 5;    
               document.getElementById('valore').value = newValue;           
        }else{
            //caratteri non consentiti = reset testo
            document.getElementById('testo').value = currentText;
        }
      }
    
    
    
    
    </script>
    </head>
    <body>
    Testo <input type="text" id="testo" value="" onKeyup="javascript:calcola(event);"/>
    Valore <input type="text" id="valore" value="0">
    </body>
    </html>
    Il codice a se stante funziona, manca la gestione per il testo, il quale comprende il caratter euro o meno.
    Il fatto che stia in un plugin è già più complesso, se devi modificare un plugin potrebbe essere legato ad altro ma non posso vedere e avere idea di cosa ci sia dietro.

    Da questo esempio bene o male puoi farti un'idea di come continuare.

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2018
    Messaggi
    20
    Quote Originariamente inviata da m4rko80 Visualizza il messaggio
    Mancava una graffa al codice(funziona calcola)
    codice:
    <html>
    <head>
    <script>
    var unit = 5;
    var min = 0;
    var currentValue;
    var currentText;
    
    
    
    
    window.onLoad = function(){
     currentValue = document.getElementById('valore').value || 0;
     currentText = document.getElementById('testo').value;
    }
    
    
    
    
    function calcola(event){
       
        var key = event.which || event.keyCode;  
    
    
    
    
        var inp = String.fromCharCode(key);
        if (/[a-zA-Z0-9]/.test(inp) || (key==8)){ //Tasti accettati : lettere e numeri
            currentText = document.getElementById('testo').value;
             console.log(key, document.getElementById('testo').value.length)
               var newValue = document.getElementById('testo').value.length * 5;    
               document.getElementById('valore').value = newValue;           
        }else{
            //caratteri non consentiti = reset testo
            document.getElementById('testo').value = currentText;
        }
      }
    
    
    
    
    </script>
    </head>
    <body>
    Testo <input type="text" id="testo" value="" onKeyup="javascript:calcola(event);"/>
    Valore <input type="text" id="valore" value="0">
    </body>
    </html>
    Il codice a se stante funziona, manca la gestione per il testo, il quale comprende il caratter euro o meno.
    Il fatto che stia in un plugin è già più complesso, se devi modificare un plugin potrebbe essere legato ad altro ma non posso vedere e avere idea di cosa ci sia dietro.

    Da questo esempio bene o male puoi farti un'idea di come continuare.
    Per farti capire meglio provo a pubblicarti il codice in questione:

    Per farti capire, in pratica va bene così come mi hai fatto vedere, soltanto che vorrei che aumentasse la cifra del prezzo, non il value. Ti pubblico il codice attuale:

    <!doctype html>
    <html>
    <head>
    <script>
    var unit = 5;
    var min = 0;
    var currentValue;
    var currentText;


    window.onLoad = function(){
    currentValue = document.getElementById('item_price').value || 0;
    currentText = document.getElementById('ricamo').value;
    }


    function calcola(event){

    var key = event.which || event.keyCode;

    var inp = String.fromCharCode(key);
    if (/[a-zA-Z0-9]/.test(inp) || (key==8)){ //Tasti accettati : lettere e numeri
    currentText = document.getElementById('ricamo').value;
    console.log(key, document.getElementById('ricamo').value.length)
    var newValue = document.getElementById('ricamo').value.length * 5;
    document.getElementById('item_price').value = newValue;
    }else{
    //caratteri non consentiti = reset testo
    document.getElementById('ricamo').value = currentText;
    }
    }
    </script>
    </head>


    <body>

    <font>5€ a lettera</font>
    <input type="text" class="ricamo"> <br>

    <span class="item_price">95.00€</span>

    <a class="item_add" href="javascript:;"><input type="submit" value="AGGIUNGI AL CARRELLO" class="add_to_cart"></a>

    </div>
    </form>
    </body>
    </html>

    Grazie al tuo esempio, riesco ad aumentare il value, soltanto che io vorrei che aumentasse la cifra , ovvero il prezzo dell' item_price.

    So che non è facile da spiegare..

Tag per questa discussione

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.