This script sets the focus to the first input field on a form using the For-Loop but I would appreciate if someone could explain how this script works? I haven’t seen a script put together like this, is there a name for this technique? Thanks much!
<script name="setFocus" language="JavaScript">
(function () {
var prev = window.onload;
window.onload = function() {
prev && prev();
for (var i = 0; i < document.findForm.elements.length; i++) {
if ((document.findForm.elements.type == 'text' && document.findForm.elements.disabled == false) || document.findForm.elements.type == 'select') {
document.findForm.elements.focus();
return;
}
}
}
}
)();
</script>
<script name="setFocus" language="JavaScript">
(function () {
var prev = window.onload;
window.onload = function() {
prev && prev();
for (var i = 0; i < document.findForm.elements.length; i++) {
if ((document.findForm.elements.type == 'text' && document.findForm.elements.disabled == false) || document.findForm.elements.type == 'select') {
document.findForm.elements.focus();
return;
}
}
}
}
)();
</script>