jasonc Posted May 30, 2011 Share Posted May 30, 2011 I have many fields in my form and wish to know how I can set them all to autocomplete off without using the autocomplete element as this does not validate properly. I have had many people say this is not best practice but still wish to add this to my form. <script type="text/javascript"> function init() { if (!document.getElementById) return false; var f = document.getElementById('auto_off'); var u = f.elements[0]; f.setAttribute("autocomplete", "off"); u.focus(); } </script> this is what i was first given and have been trying to figure out how i alter this so i can search for all fields and change them without having to add a div to each one as this would be the only way as i have already used the name and the id elements for other things. also having a script with multiple lines for each and every field is not practicle as there are loads of them. any advise on how i might be able to do this ? Quote Link to comment https://forums.phpfreaks.com/topic/237844-make-all-fields-in-form-autocompleteoff/ Share on other sites More sharing options...
seanlim Posted May 30, 2011 Share Posted May 30, 2011 Try using document.getElementsByTagName? var e = document.getElementsByTagName('input'); for(var i=0; i<e.length; i++) { if(e[i].type == 'text') e[i].setAttribute('autocomplete', 'off'); }; Quote Link to comment https://forums.phpfreaks.com/topic/237844-make-all-fields-in-form-autocompleteoff/#findComment-1222242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.