views:

115

answers:

5

Is there a way to turn off auto-complete on an input-field using jQuery?

Like this:

<input type="text" autocomplete="off" />
+5  A: 
$(':text').attr('autocomplete', 'off');
Andreas Niedermair
Thanks a bunch! :D
timkl
you're welcome :)
Andreas Niedermair
+1  A: 
$('input#id').attr('autocomplete', 'off');

You can also use a common class to turn off a group of fields. There are a few ways to do it though as you'll see from the answers.

Kevin
Forgive me, already edited it. Was in the midst of working with an array and slipped.
Kevin
:) removed downvote
Andreas Niedermair
The same can be done with your query. `$('#id').attr('autocomplete', 'off');`
The Elite Gentleman
+1  A: 
$('#id').attr('autocomplete', 'off');
Bryan Denny
+1  A: 

For any text field, you could do this.

$("input[type=text]").attr("autocomplete", "off");

Hope this helps!

The Elite Gentleman
A: 

"autocomplete" isn't a standard attribute. Yes it's implemented, but it's not proper XHTML.

Do you have to do it client-side? Can you make changes on the server-side if necessary?

Pickle
I know it isn't standard XHTML, but I need for validation purposes. The reason why I need to add it with jQuery is due to the fact that the developers are using Struts and it doesn't allow you to put autocomplete="off" on as an attribute on the Struts html-tag.
timkl
Actually, you can by using EL and JSTL workaround.
The Elite Gentleman
Cool, I'll pass it on - so much knowledge on this forum! :)
timkl