Disabilitare alcuni tasti in javascript

Ho trovato questo script semplice e ben fatto, che ha l’ottimo pregio di funzionare sia con Explorer che con Firefox. L’ho trovato qui:

www.arraystudio.com/as-workshop

Lo script è il seguente:

<script language=“JavaScript”>
function disableEnterKey(e)
{
var key;

if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox

if(key == 13)
return false;
else
return true;
}
</script>

Chiamato nella pagina HTML:

<input type=”text” name=”mytext” onKeyPress=”return disableEnterKey(event)”>

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>