Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Tab Key Emulation



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
tramarcelo



Joined: 08 May 2007
Posts: 1

PostPosted: Tue May 08, 2007 9:11 am    Post subject: Tab Key Emulation Reply with quote

Hi, i've been using this function to make the enter key behave like a tab key. instead of using the tab key, the user can now use the enter key to go to the next field... however, what i want to happen is let the enter key function as it is when it reaches the submit button. can anyone please help me revise the code below. thanks.


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;

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;");
}

}
Back to top
View user's profile Send private message
mwa103
100+ Club


Joined: 07 Mar 2005
Posts: 206

PostPosted: Wed May 09, 2007 3:38 pm    Post subject: Re: Tab Key Emulation Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap