Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Script conta caratteri

  1. #1

    Script conta caratteri

    Salve ho questo script che mi convalida un campo se l'utente ha scritto almeno 60 caratteri nell'input.

    codice:
    <input type='text' maxlenght='580' name='Testo' size='95' class='BTN' onkeyup="if(this.value.charAt(0)=='+' && this.value.length<60) { this.className='VABENE';} else {this.className='NONVA'; }">
    ora vorrei attuare una piccola modifica. Cioè lo script non deve contare gli spazi come caratteri. Quindi l'utente deve scrivere 60 caratteri al di la degli spazi tra le varie parole.

    Come faccio?

    thx
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  2. #2
    Ciao,
    io farei così:

    sostituire tutti gli spazzi con "" in modo da azzerare gli spazi vuoti e poi conterei la lunghezza della stringa.


    function getLength(id){
    var elem = document.getElementById(id);

    var strTemp = elem.value;

    strTemp = strTemp.replace(" ","");

    return strTemp.length;
    }

    Provala e fammi sapere
    Ciao
    Mirko Agrati
    WEB : http://mirkoagrati.110mb.com
    RSS : http://feeds.feedburner.com/MirkoAgratiArticoli

  3. #3
    quindi verrebbe una cosa del gnere?

    codice:
    <script language='javascript'>
    function getLength(id){
    var elem = document.getElementById(id);
    
    var strTemp = elem.value;
    
    strTemp = strTemp.replace(" ","");
    
    return strTemp.length;
    }
    </script>
    
    <input type='text' id='Testo' name='Testo' onkeyup="if(this.value.charAt(0)=='+' && getLength(Testo)<60) { this.className='VABENE';} else {this.className='NONVA'; }">

    ??
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  4. #4
    hai provato?
    Mirko Agrati
    WEB : http://mirkoagrati.110mb.com
    RSS : http://feeds.feedburner.com/MirkoAgratiArticoli

  5. #5
    si non va...
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  6. #6
    Ciao,
    ma ti da problemi a runtime?

    Altrimenti

    <input type='text' id='Testo' name='Testo' onkeyup="if(this.value.charAt(0)=='+' && getLength(Testo)> 60) { this.className='VABENE';} else {this.className='NONVA'; }">
    Mirko Agrati
    WEB : http://mirkoagrati.110mb.com
    RSS : http://feeds.feedburner.com/MirkoAgratiArticoli

  7. #7
    io la vedo cos&igrave;:
    codice:
    <script language='javascript'>
    function getLength(elem){
        var strTemp = elem.value;
        strTemp = strTemp.replace(" ","");
        return strTemp.length;
    }
    </script>
    poi chiamata cos&igrave;:
    codice:
    <input type='text' id='Testo' name='Testo' onkeyup="if(this.value.charAt(0)=='+' && getLength(this)> 60) { this.className='VABENE';} else {this.className='NONVA'; }" />
    HTH
    Zappa
    [PC:Presario 2515EU][Cpu:P4@2.3GHz][Ram: 512M][HDU:80G@5400 RPM]
    [Wireless:LinkSys][OS: Ubuntu 9.04 - Jaunty Jackalope]

  8. #8
    Originariamente inviato da homezappa
    io la vedo cos&igrave;:
    codice:
    <script language='javascript'>
    function getLength(elem){
        var strTemp = elem.value;
        strTemp = strTemp.replace(" ","");
        return strTemp.length;
    }
    </script>
    poi chiamata cos&igrave;:
    codice:
    <input type='text' id='Testo' name='Testo' onkeyup="if(this.value.charAt(0)=='+' && getLength(this)> 60) { this.className='VABENE';} else {this.className='NONVA'; }" />
    HTH
    Zappa
    non cambia nulla. Va ma conta lo stesso gli spazi. Se scrivo 60 spazi me li accetta
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

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.