So, I've got this code:
$(document).ready(function(){
$('form').attr('autocomplete', 'off');
});
It works great for all forms already existing. The problem is, some forms of mine are in pop ups loaded throught ajax. This won't apply to them since they're "loaded" later.
I know there's a live() function - but that's only for attaching events. What's a good way to apply this to all forms?
Thanks.
To disable the autocomplete of text in forms, use the autocomplete attribute of <input> and <form> elements. You'll need the "off" value of this attribute.
Autocomplete attribute of HTML is use to fetch previous input values in input fields. Almost all browsers supports autocomplete attribute, by default this attribute is “on” in html. If you want to disable this attribute ,you can set autocomplete=”off” in html input tag.
Add autocomplete="off" onto <form> element; Add hidden <input> with autocomplete="false" as a first children element of the form.
Autocomplete is a default feature of most modern web browsers. It anticipates what you are typing and suggests a word or phrase based on the activity of other users and your history. If you press Enter , the application automatically completes your typing with the remainder of the suggested text.
You could bind a live event to the focus event and then change the attribute on that.
$(document).ready(function(){
$(':input').live('focus',function(){
$(this).attr('autocomplete', 'off');
});
});
As of jQuery 1.7 jQuery.live was deprecated. This code would now look like:
$(document).ready(function(){
$( document ).on( 'focus', ':input', function(){
$( this ).attr( 'autocomplete', 'off' );
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With