Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di gppjuse
    Registrato dal
    Apr 2002
    Messaggi
    238

    Sostituire la virgola con il punto

    Salve,

    ho provato a modificare il codice di sotto che serve a controllare i caratteri che vengono immessi all'interno di un campo di testo:

    codice:
    <!--
    function getkey(e)
    {
    if (window.event)
       return window.event.keyCode;
    else if (e)
       return e.which;
    else
       return null;
    }
    //-->
    
    
    <!--
    function caratteriok(e, goods)
    {
    var key, keychar;
    
    
    key = getkey(e);
    if (key == null) return true;
    
    
    // get character
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    
    
    goods = goods.toLowerCase();
    
    
    // check goodkeys
    if (goods.indexOf(keychar) != -1)
        return true;
    
    
    // control keys
    if ( key==null || key==0 || key==8 || key==9 
        || key==13 || key==27 )
       return true;
    
    
    // else return false
    return false;
    }
    //-->
    Lo script si attiva inserendo onKeyPress="return caratteriok(event,'0123456789.,')" sul campo di testo. Quello che vorrei ottenere è, SE viene digitato il carattere della virgola, questa venga cambiata con il segno del punto.

    Grazie per l'aiuto.
    Solo chi non osa...non sbaglia!

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    onKeyPress="this.value.replace(',','\.');return caratteriok(event,'0123456789.,')"
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Utente di HTML.it L'avatar di gppjuse
    Registrato dal
    Apr 2002
    Messaggi
    238
    Non funziona. Così però funziona:
    onKeyPress="this.value = this.value.replace(',','\.'); return caratteriok(event,'0123456789.,')"
    Ultima modifica di gppjuse; 04-02-2014 a 23:44
    Solo chi non osa...non sbaglia!

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.