Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    273

    Problema Campo di testo

    Ho un campo di testo chiamato 'Prezzo Unitario'.
    Vorrei fare in modo che se l'utente digita 20 e passa al campo successivo, il valore 20 si trasforma in 20.00.
    Mentre se l'utente digita il punto (ad esempio 20.50) il valore rimane inalterato.
    E' possibile??
    Grazie!

  2. #2
    codice:
    <?xml version="1.0" encoding="iso-8859-1"?>
    
    
      <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
        <head>
          <title>Esempio di Codice</title>
    
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <meta http-equiv="Content-Language" content="it" />
    
          <script type="text/javascript" language="JavaScript">
          <!--
    
            /*
    
              checkFloat( <riferimento all'oggetto> [, <numero di cifre decimali> ] );
    
            */
    
            function checkFloat( __hItem, __decimalPos )
            {
              if ( __hItem == null )
                return false;
    
              if ( __decimalPos == null || __decimalPos < 0 )
                __decimalPos = 0;
    
              var decDigit = Math.pow(10, __decimalPos);
              var strValue = Math.round(parseFloat(__hItem.value.replace(/,/, '.')) * decDigit ) / decDigit;
    
              if ( isNaN(strValue) )
                strValue = 0;
    
              strValue     = strValue.toString();
              var decPos   = strValue.indexOf('.');
    
              if ( decPos == -1 ) {
                decPos    = 0;
    
                if ( __decimalPos > 0 )
                  strValue += '.';
              }
              else
                decPos    = strValue.length - decPos - 1;
    
    
              for (var i=0; i<__decimalPos-decPos; i++)
                strValue += '0';
    
              __hItem.value = strValue;
              return true;
            }
    
          //-->
          </script>
        </head>
    
        <body>
    
          <form action="//" onsubmit="return false;">
    
            Prezzo #1: <input type="text" onblur=" checkFloat(this, 0); " /> (senza decimali)
    
            Prezzo #2: <input type="text" onblur=" checkFloat(this, 1); " /> (1 cifra decimale)
    
            Prezzo #3: <input type="text" onblur=" checkFloat(this, 2); " /> (2 cifre decimali)
    
            Prezzo #4: <input type="text" onblur=" checkFloat(this, 3); " /> (3 cifre decimali)
    
            Prezzo #5: <input type="text" onblur=" checkFloat(this, 10); " /> (10 cifre decimali)
    
          </form>
    
        </body>
    
      </html>
    DYNAMIC+ [ E-mail ]

    Secondo me non si può fare!

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    273
    Grazie mille!!

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.