Posts Tagged ‘ ajax

How to limit a field with javascript-prototype and display the counter

For job purposes I had to learn a lot of JavaScript, including AJAX related stuffs. Like every lazy (but intelligent) developer, I looked around for frameworks that could help me doing my work. I knew that prototype existed, but I never looked at it because of lack of interest. Well it’s great, it’s really great! Nowadays everybody should use frameworks, as their abstraction permits a rapid development without worrying about things like platform compatibility, in our case browsers. Prototype also has a very nice and clean syntax that overtakes functions not compatible with every browser.

In this post I’m going to report a very nice function I implemented for limiting Form input fields, like textarea and input of type text. You have to call it via onkeyup and onkeydown events. The function accepts 3 parameters: field, limit and counterDesired.
The first is the field object, you should use the keyword this for a value.
The second parameter is a limit value, the number of characters that the field should contain at maximum.
The third parameter is optional, false as default. It permits to add a visual counter after the field, like the one you see on YouTube, for example. You can either tell to the function to add the counter for you (put inside a <span> block) or to put it inside another block you’ve already defined. In the second case, the block must have an id of the form ‘fieldID_counter’

This is the compact version, see below for some examples and the expanded, explained version:

<script type="text/javascript">
// < ![CDATA[
function limit_text(field, limit, counterDesired) {
    if (counterDesired == null)
        counterDesired = false;
    var length = $F(field).length;
    if (length > limit)
        $(field).value = $(field).value.substring(0, limit);
    if (counterDesired) {
        if ($($(field).id + '_counter')) {
            $($(field).id + '_counter').update($F(field).length + " / " + limit);
        } else {
            var counterText = new Element('span', {'id': $(field).id + '_counter'});
            counterText.update($F(field).length + " / " + limit);
            $(field).insert({'after': counterText});
        }
    }
}
// ]]>
</script>
 

Read more

Related posts

Curriculum

Download Curriculum formato PDF

Dati anagrafici

  • Daniel Graziotin
  • Nato a Bolzano il 23 Aprile 1987
  • Residente in Via San Giacomo n. 13,
 39055 Laives (BZ)
  • Patente: A,B
  • Telefono cellulare: +39 3400788910 - Telefono fisso: +39 0471251310
  • E-mail: bodom_lx email

Istruzione e Formazione

  • 2006 – Maturità scientifica 88/100 presso “Liceo Scientifico Europeo Rainerum”
di Bolzano
  • Studente di Informatica Applicata alla Libera Università di Bolzano 
(Bachelor of Science in Applied Computer Science)

Esperienze Professionali

Lingue Straniere

  • INGLESE: ottima conoscenza della lingua parlata e scritta (C1)
  • TEDESCO: buona conoscenza della lingua parlata e scritta
 (B2)

Certificazioni

  • Zertifikat Deutsch für den Beruf del Goethe Institut (Tedesco Orale e Scritto livello B2)
  • Certificate in International ESOL di City and Guilds (Inglese Scritto livello Expert-C1)
  • Certificate in International Spoken ESOL di City and Guilds (Inglese Orale livello Expert-C1)
  • Certificazione WebValley 2005
  • European Computer Driving License (ECDL)
  • Patentino Bilinguismo C

Pubblicazioni

Portfolio

Conoscenze informatiche

Sistemi Operativi:

  • Gnu/Linux, 8 anni ambiente Desktop, 6 anni Server, sviluppo applicazioni Web
  • Windows, 11 anni Desktop, 1 anno Server
  • Mac OS X ambiente Desktop

Linguaggi di Programmazione/Markup/Stile/Query

  • HTML/XHTML – CSS – Javascript/Ajax - PHP – SQL: livello ottimo
  • Java – C/C++ : livello ottimo
  • Python – ASP(VBscript) – LaTEX: livello buono
  • BasicX – NQC (linguaggi per programmazione microcontrollori): livello buono
  • Basi di molti altri linguaggi, nessuna difficoltà di apprendimento

Esperienze Formative

  • Sviluppo di una social network per il car-pooling in Italia, in Python Django
  • Sviluppo di un progetto opensource in C++ (QT) per la gestione di attività secondo la Tecnica del Pomodoro
  • Sviluppo di un portale dinamico a scopo accademico in Java EE5 (Servlets e JSP)
  • Sviluppo di una mini shell per sistemi Unix in C
  • Sviluppo di una versione opensource del popolare gioco Monopoli della Hasbro, in Java
  • Sviluppo di due CMS in PHP5 per Bizetaweb, uno per la gestione di Alberghi, l’altro per la gestione di Aziende (dettagli e immagini disponibili nel portfolio)
  • In Thun S.p.a,: Esperienza come sistemista, amministratore di rete in ambiente Windows 2003 e Windows 2000, basi di amministrazione Ibm Lotus Notes / Lotus Domino
  • Gestione di un server virtuale con Debian Gnu/Linux come sistema operativo
  • Pubblicazione di guide per configurare parti hardware sul wiki ufficiale di Ubuntu, e altri siti su Fedora e OpenSuSE.
  • Sviluppo e gestione di tracker BitTorrent in PHP (il maggiore da 150.000 utenti) negli anni 2004 e 2005; contatti con i grandi nomi di BitTorrent per eventuali progetti futuri
  • 1° posto Nord Italia per il concorso “Con computer ed Inglese conquisti il tuo futuro” (Acer, Trinity, Microsoft, English Town, Parlamento Europeo) nel 2004
  • Stage WebValley 2005, ITC, IRST, Iprase di Trento; sviluppo del sistema prototipo LUGORT per la raccolta, l’analisi e la visualizzazione interattiva di dati biologico-ambientali. (altre info: http://mpa.itc.it/webvalley/webvalley2005/ReportWebValley2005-PAT.pdf)
  • Stage formativo al Museo Civico di Rovereto per la programmazione di robot Lego Mindstorms nel 2005
  • Corso sull’uso di LabView nel 2003
  • Tre anni di frequenza laboratori pomeridiani orientati alla robotica ed organizzati dal Liceo Scientifico Europeo Rainerum. Contributi nelle realizzazioni dei robot apparsi spesso alla televisione locale
  • Tre viaggi studio della durata di tre settimane ciascuno in Germania
  • Un viaggio studio della durata di dieci giorni in Inghilterra

Download Curriculum formato PDF

Related posts