Flash Games

 FAQ   Search   Members   Groups   User Control Panel      Login 

It is currently Thu Jan 08, 2009 11:44 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Tab Key Emulation
PostPosted: Tue May 08, 2007 9:11 am 
Offline

Joined: Tue May 08, 2007 9:00 am
Posts: 0
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;");
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 3:38 pm 
Offline
100+ Club

Joined: Mon Mar 07, 2005 11:55 pm
Posts: 206
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review

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: