File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Ajax, autocomplete and JavaScript (or CSS) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax, autocomplete and JavaScript (or CSS)" Watch "Ajax, autocomplete and JavaScript (or CSS)" New topic
Author

Ajax, autocomplete and JavaScript (or CSS)

Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
IE has the annoying issue with autocomplete text boxes where if you select an item from the autocomplete list the onchange event is not fired. Does Firefox have the same "feature"? Turning off autocomplete for specific forms or textboxes would be a simple task, but I am using Struts tags which do not support this.

I would rather not screw around with subclassing the Struts html:text tag and changing pages over to use the subclassed tag. The thought occurred to me that I could turn off autocomplete via JavaScript or CSS. I don't know jack about CSS and I only know a little more that that about JavaScript and manipulating DOM objects. I tried a few things and the following seemed to work:


Some limited tested showed that this worked for IE 6, but did not do anything for Firefox. (I technically only have to support IE, but I would rather have a cross browser solution). Does anybody have an elegant way of turning off autocomplete via JavaScript or CSS?

BTW, the purpose of this post was not how to deal with the Ajax/autocomplete/onchange issue, but if somebody can point me to an elegant solution or provide information on the typical way of dealing with this I would love to hear it.

- Brent
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You could use onblur on the element instead of onchange.

You can try

document.formName.elementName.setAttribute("autocomplete","off");

Eric
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Eric: Thanks for the reply. I am not sure I want to switch over to onblur. It seems like as it is I will be making quite a few Ajax calls when somebody is filling out a form. I am not sure I would want to make Ajax calls when the user it tabbing through the form and not changing values. I am pretty new to Ajax, but I thought that onchange was the most common event to use. Am I wrong?

I just hooked up the call to setAttribute and it is working in IE and Firefox. That seems good enough to me so I will go with that solution. I am almost positive that the security policy in place by my client requires that users turn off autocomplete in their browser settings so it is probably not a huge deal in any case.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax, autocomplete and JavaScript (or CSS)
 
Similar Threads
Need help on JQUERY/AJAX support with Blackberry Simulator 9700
Preventing from browser caching data?
turn autocomplete off in Struts?
form/input tags and turning off autocomplete
pass <bean:write> to a function