Io continuo a ritenere che programmare senza jQuery fa guadagnare anni luce in chiarezza…:
codice:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio</title>
<script type="text/javascript">
(function () {
var rDeny = /"/;
function filterInput (oEvent) {
var nChr = (oEvent || /* IE */ window.event).charCode;
return nChr === 0 || !rDeny.test(String.fromCharCode(nChr));
}
function createFilter () {
for (var aTxtBoxes = document.getElementsByClassName("filtered"), nLen = aTxtBoxes.length, nItem = 0; nItem < nLen; nItem++) {
aTxtBoxes[nItem].onkeypress = filterInput;
}
}
window.addEventListener ? addEventListener("load", createFilter, false) : window.attachEvent ? attachEvent("onload", createFilter) : (onload = createFilter);
})();
</script>
</head>
<body>
<form name="myForm">
Esempio #1: <input type="text" name="myInput1" class="filtered" /></p>
Esempio #2: <input type="text" name="myInput2" class="filtered" /></p>
Esempio #3: <input type="text" name="myInput3" class="filtered" /></p>
</form>
</body>
</html>