Earlier, I was testing an online form on a project I am working on and noticed I couldn't actually type anything in any of the form fields. I narrowed it down to a specific script. And I think it's this bit right here in the code causing the problem since when I remove it, I can type again.
$(document).on('keypress', handleEvent);
But for the life of me I have no idea why it's happening and I'm not sure how to go about fixing it. Any help in pointing out what's wrong and how to fix this would be appreciated.
jQuery(document).ready(function($) {
function handleEvent(e){
var id = null;
var fade_out;
var fade_in;
if (e.type === 'click'){
id = $(this).attr("id");
}else{
id = e.which;
}
switch (id){
case 13:
if ($('#click_1').is(':visible')){
fade_out = '#start_1';
fade_in = '#step_0';
}
break;
..etc..
default:
break;
}
$(fade_out).fadeTo( 'fast', 0 );
$(fade_in).delay( 800 )..fadeTo( 'slow', 1 );
e.preventDefault();
}
$('#ts_container').on('click', 'button, a', handleEvent);
$(document).on('keypress', handleEvent);
});
Update
I figured out a way to fix it. But, still no idea why it was happening.
Replaced:
$(document).on('keypress', handleEvent);
With:
if ($(document).keydown(function(e){
if ($('#service_form').is(':hidden')){
$(document).on('keyup', handleEvent);
}
}));