trying to write a function that will set focus to first form element that is not a hidden input. This is not working but also not producing an error. any suggestion? function setFocus(){ for(var i=0;i< document.forms[0].elements.length;i++){ if(document.forms[0].elements.type != 'hidden'){ document.forms[0].elements.focus(); break; } } }