开发者

How do I determine whether data on a form has been input by the user or the browser?

I have a checkout form that will display a pop-up survey to ask why they haven't started filling out the form after 5 seconds. However, I need to be able to check whether the user has actually entered data as opposed to data entered by the browser's auto-fill feature (any pre-populated data set in the markup I specifically ignore in the javascript or jQuery).

Right now my solution is to have the setTimeout run a function which checks a variable (true or false) that is set to false on a jQuery .focus or .change event on the input types (input, select, textarea). However, since the javascript may load after the user is able to use the form elements, I have to check whether the user has entered data before the survey pops up.

Is it possi开发者_如何学Pythonble to differentiate between user-inputted data and browser-inputted data if the javascript loads after the user has done anything to the form fields?


If you really want to tell browser not to autofill it at all, you could use autocomplete attribute, but this is unfortunately an invalid attribute and thus will not validate. If you really need your HTML to validate, you can use jQuery to do just that for you:

$(your_form_selector).attr('autocomplete', 'off');

More discussion about autocomplete here


What about .keyup event for form?

var isFilledByUser = false;
$("#input").keyup(function(){
    var isFilledByUser = true;
});


ok... this was mildly entertaining, but I definitely agree... this feature would be so annoying XD

http://jsfiddle.net/NTvrN/1/

but there you go... now type, foo!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜