venerdì 26 marzo 2010

Script javascript per trasformare i caratteri in maiuscolo

Eccovi un piccolo script per jquery, realizzato da me, per trasformare in maiuscolo i caratteri digitati in una textarea.

$(document).ready(function() {

$("input, textarea").live('keypress', function(e){
var key;
var val1;
//se è IE
if (window.event){
key = e.keyCode;

if ((key > 0x60) && (key < 0x7B) || key == 232
|| key == 242 || key == 224 || key == 249 || key == 236
|| key == 233){
key = key-0x20;
}
//tutti gli altri browser
}else{
key = e.which;

if ((key > 0x60) && (key < 0x7B) || key == 232
|| key == 242 || key == 224 || key == 249
|| key == 236 || key == 233){
key = key-0x20;
}
}
// fa in modo che prenda gli altri eventi come il
backspace oppure ctrl+v o ctrl+c
if (key == 8 || e.ctrlKey || e.altKey || key == 0){
return;
}

val1 = $(this).val();
$(this).val(val1 + String.fromCharCode(key));
return false;

});



0 commenti:

Posta un commento