Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make text input fields remember previously entered data

Tags:

My text inputs seem not to remember values that have been typed before. For example, many websites that I don't even have an account on, but have, for example entered my email address before (buying a train ticket as a "guest") give me a sort of dropdown with email addresses I've used in the past. Yet my form does not do this. It obliges me to type it out completely every time. It seems to be the opposite of this question...

I have simple inputs like <input type="text" id="firstName" placeholder="First name" />

And they are submitted with simple a jQuery Ajax post. Something like this. However the Ajax isn't working on jsbin on that example, I just show it to demonstrate my basic structure. Is there a jQuery plugin for this? Is there a way I can control this seemingly browser-driven behavior?

like image 380
1252748 Avatar asked May 08 '13 15:05

1252748


People also ask

How do I clear the previous text field value after submitting the form with out refreshing the entire page?

The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method to submit the form.


2 Answers

In most browsers, you can make your browser display values previously entered in input fields by giving a name to the input. For example:

<input type="text" id="firstName" placeholder="First name" name="firstName" > 

If the field has no name attribute, the browser won't show suggestions.

Also check if javascript prevents the default action on submit.

like image 81
Georgios Balasis Avatar answered Sep 24 '22 03:09

Georgios Balasis


I had the same problem. For me, it was when developing in ASP.NET MVC. Anyway, the solution I had to make was a combination of things:

  1. Having the name attribute defined in my input tags

  2. Having autocomplete="on" in my input tags

  3. Changing the button tag to be a type="submit" tag

  4. Enclosing all my input controls in a <form> tag

like image 43
Jeff Moretti Avatar answered Sep 24 '22 03:09

Jeff Moretti