Preventing browser autocompleting form fields

To prevent the browser to remember all of the values that have been filled in in a form field you can use the "autocomplete" parameter :

<input id="myPass" name="pass" size="20" type="password" />

But this will incalidate your HTML code.. Therefor if you want to do the same but still want your code to pass through the validator there is a JavaScript work around:

1
2
3
4
5
6
7
function init() {
	if (!document.getElementById) return false;
	var f = document.getElementById('auto_off');
	var u = f.elements[0];
	f.setAttribute("autocomplete", "off");
	u.focus();
}
<body onload="init()">
<form id="auto_off" method="get"></form>
No comments yet.
No trackbacks yet.
  • My latest tweets

    Follow me on Twitter!