Try this one, this function allows alphanumeric and spaces:
function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
in your html:
<input type="text" name="name" onkeypress="return alpha(event)"/>