Autocomplete=”off” workaround / fix for valid XHTML

Add an onload function similar to the following to <head> section of your web page.

<script type="text/javascript">
function onload_call() {
if (!document.getElementById) return false;
var f = document.getElementById('field_name');
f.setAttribute("autocomplete", "off");
}
</script>

Call onload_call() function as page/body onload call as below and you are done.

<body onload='onload_call()'>
<input type='text' id='field_name' value='' /> Field label

If you are on jQuery you can add a similar snippet of js code to below to your webpage (anywhere at a valid place of course)

$(document).ready(function() {
$("#field_name").attr("autocomplete", "off");
});

2 thoughts on “Autocomplete=”off” workaround / fix for valid XHTML

  1. Alternative for jQuery;
    $(function(){$(“#field_id”).attr(“autocomplete”, “off”);});

Leave a Reply