waytofall
waytofall

Reputation: 383

How to coorporate with the autocomplete provided by a browser using javascript

I'm doing some demos on javascript. I regiester a onkeypress event on a text input and check that if it's "enter" key to auto submit a form. The browser has a autocomplete function (mine is firefox), which may select from a dropdown list using the up/down arrow and a enter key. The problem is that when the input text is focused and the autocomplete is shown, you press enter button just to select the autocomplete item, but it auto submits the form at the same time. How to avoid this? How can I retrieve the autocomplete element from browser using javascript ??

Upvotes: 3

Views: 88

Answers (2)

closure
closure

Reputation: 7452

No browser will ever give autocomplete information to the program. That would be a way to steal data and hence a security threat. Imagine, my program wishes to steal your address, so when you access my page, I keep an address text box and take all the address values you have filled in past.

As suggested in the comments, you can set autocomplete to off to avoid showing a dropdown.

Here is a link How to Turn Off Form Autocompletion with explanation on this subject.

Upvotes: 1

SaidbakR
SaidbakR

Reputation: 13534

It is not allowed. It may be regarded as a security hole if it supposed to be done on any web browser.

Suppose that your website visitor tried to search for a keyword like "p*rn" so you as a website owner able to know that user like p*rn!. It is just a little example to show the security and privacy issue that your request may be.

Upvotes: 1

Related Questions