1

I have a form with an input field and I want to know if the user really filled that fileld, with a keystroke. I want to not allow the form being sent if the user used javascript to set the value of the field.

I know I can listen to keydown, keyup and keypress events in the input field to make sure the user indeed filled the input BUT it's very easy to the user to trigger those events with javascript like:

$('#my_input').focus();
$('#my_input').val("xxxx");
$('#my_input').keydown();
$('#my_input').keypress();
$('#my_input').keyup();
$('#my_input').blur();

If the user uses this javascript above he could fill the input and "simulate" he really did that. So how can I check if the user really filled the input, whether typing the content or pasting?

THIS IS A DIFFERENT QUESTION. NOT even close to a duplicated.

  • This is a bad idea in general. It'd block cutting-and-pasting, voice entry, all sorts of alternate inputs that many people depend on. Plus, it'd be just plain annoying for a lot of other people that want to use something as simple as browser auto-fill. Plus, as you point out, it's rather futile as a user can emulate this all anyways. – DA. Jun 05 '15 at 20:52

0 Answers0