Force auto-complete on form fields

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>