• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax, autocomplete and JavaScript (or CSS)

 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use onblur on the element instead of onchange.

You can try

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

Eric
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic