I am trying to deactivate the use of space bar while the user is entering his/her username in a textfield.
I tried this code which I got it from here deactivate space bar in js , which did not work at all with me, here is the JS code:
$('#checkusername').keydown(function(e) {
if (e.keyCode == 32) {
return false;
}
});
and here is my textfield text:
<input class="input_field_12em required userUserName" name="userUserName" id="checkusername">
I have replaced the
return false;withe.preventDefault()and it’s working fine for me:http://jsfiddle.net/wpJKj/1/