prova questo codice se fà al caso tuo ...
E' codice di mia mano non di terzi...
codice:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
<script language="javascript" type="text/javascript">
function numbersonly(myfield, e, dec) {
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789,").indexOf(keychar) > -1))
return true;
// decimal point jump
else if (dec && (keychar == ",")) {
myfield.form.elements[dec].focus();
return true;
} else
return false;
}
function alfanumonly(myfield, e, dec) {
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789,abcdefghilmnopqrstuvzwxykjABCDEFGHILMNOPQRSTUVZWXYKJ@#.:;").indexOf(keychar) > -1))
return true;
// decimal point jump
else if (dec && (keychar == ",")) {
myfield.form.elements[dec].focus();
return true;
} else
return false;
}
function VisualizzaInput(valore) {
alert("Hai digitato " + valore);
}
</script>
</head>
<body>
<p>Programma di esempio per avere un input controllato a monte dell'input utente su un form web </p>
<p>La verifica del campo non è piu necessaria in quanto il campo di input permette l'inserimento di soli caratteri consentiti</p>
<p> </p>
<p>1) Caso numerico: il campo accetta numeri e la virgola</p>
<p>INPUT NUMERICO
<input type="text" name="camponumerico" id="camponumerico" maxlength="15" size="20" value="" style="text-align:right;"
title="campo numerico..." onKeyPress="return numbersonly(this, event)" />
<input type="button" onclick="VisualizzaInput(camponumerico.value)" value=" verifica " /></p>
<p>2) Caso alfanumerico: il campo accetta i caratteri alfanumerici e alcuni caratteri speciali da una tabella predisposta</p>
<p> "0123456789,abcdefghilmnopqrstuvzwxykjABCDEFGHILMNOPQRSTUVZWXYKJ@#.:;" </p>
<p>INPUT ALFANUMERICO
<input type="text" name="campoalfanum" id="campoalfanum" value="" maxlength="50" size="50" style="text-align:left;"
title="campo numerico..." onkeypress="return alfanumonly(this, event)" />
<input type="button" onclick="VisualizzaInput(campoalfanum.value)" value=" verifica " /></p>
€
</body>
</html>