# Force auto-complete on form fields

**URL:** <https://forum.kirupa.com/t/force-auto-complete-on-form-fields/307316>\
**Category:** open source\
**Created:** [April 1, 2010, 1:15pm UTC](https://forum.kirupa.com/t/force-auto-complete-on-form-fields/307316 "2010-04-01T13:15:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swooter](https://avatars.discourse-cdn.com/v4/letter/s/e9a140/32.png) [@Swooter](https://forum.kirupa.com/u/Swooter)\
**Post date:** [April 1, 2010, 1:15pm UTC](https://forum.kirupa.com/t/force-auto-complete-on-form-fields/307316/1 "2010-04-01T13:15:09Z")

</div>

I made a simple script that enables autocomplete on input fields that aren’t submitted by a form.

For example, when sending forms with xmlHttpRequest, the autocomplete won’t work for those fields. Using my code will change that…

Tested and working in IE and Firefox.

Example Ajax form:  
**\<input type=“text” name=“firstname” /\>  
\<input type=“text” name=“lastname” /\>  
\<input type=“text” name=“email” /\>  
\<a href="#" onclick=“ajax.send()”\>Send\</a\>**

Example Ajax form with autocomplete has to be wrapped inside a \<form\> tag:

**\<form action=""\>  
\<input type=“text” name=“firstname” /\>  
\<input type=“text” name=“lastname” /\>  
\<input type=“text” name=“email” /\>  
\</form\>**  
\*\*\<a href="#" onclick=“forceAutoComplete();ajax.send()”\>Send\</a\>

\<script type=“text/javascript”\>  
//\<![CDATA[  
function forceAutoComplete() {  
var $forms = document.getElementsByTagName(“FORM”);  
for ( var i = 0; i \< $forms.length; i++ ) {  
var $form = $forms\*;  
var $submit = document.createElement(“INPUT”);  
$submit.type = “submit”;  
$form.appendChild($submit);  
$form.onsubmit = function(){return false}  
$submit.style.display = “none”;  
$submit.click();  
}  
}  
//]]\>  
\*\*\</script\>
