Not 100% sure I'm following your code, but you could try:
Code:
function enterToTab(formRef, focusAny)
{
/***(C)'Arty Effem'
In all text/password elements of the specifed form, plus /empty/ textareas,
Enter key 'tabs' to:
focusAny==true: next visible element,
focusAny==false: next text/textarea/pw
***/
for(var i=0, e=formRef.elements, len=e.length, hasNext=true; i<len && hasNext; i++)
if( e[i].type && /^text|password|file|submit/.test( e[i].type ) )
{
for(var j=i+1; j<len && (!e[j].type ||( focusAny ? /hidden/.test(e[j].type): !/^text|password|file|submit/.test(e[j].type)) ); j++)
;
hasNext = j!=len;
//Changed\\
if(hasNext)
{
e[i].onkeypress=new Function("var ta=false,k=(arguments[0]?arguments[0].which:window.event.keyCode )!=13;\
if(!k && !(ta=(this.type=='textarea'&&this.value.length>0)) && "+hasNext+")this.form.elements["+(j)+"].focus(); return k||ta;");
}
}
}
Not sure if that will work or not, but I'll fill you in on what I'm thinking. If the element doesn't have a next element (hasNext==false) then it should be the submit button (correct me if I'm wrong). So only do the onkeypress check if hasNext==true.
Hope this helps.
-Mike