# On keyPress "TAB", Selection.setFocus("NEXT TEXTFIELD")

**URL:** <https://forum.kirupa.com/t/on-keypress-tab-selection-setfocus-next-textfield/286604>\
**Category:** Uncategorized\
**Created:** [April 17, 2009, 4:09pm UTC](https://forum.kirupa.com/t/on-keypress-tab-selection-setfocus-next-textfield/286604 "2009-04-17T16:09:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pantas](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@pantas](https://forum.kirupa.com/u/pantas)\
**Post date:** [April 17, 2009, 4:09pm UTC](https://forum.kirupa.com/t/on-keypress-tab-selection-setfocus-next-textfield/286604/1 "2009-04-17T16:09:10Z")

</div>

hi there. well, i’ve been trying to fix this bug in a form:

when i press TAB, the selection goes to another movieclip, instead of the next text field.  
i read a lot of threads, but could’t fix this bug, so i hope someone can help me out.

so far (after lots), i got this code:  
[AS]  
var textAR:Array = [“nome\_txt”, “contacto\_txt”, “email\_txt”, “morada\_txt”, “pais\_txt”]  
var textCounter:Number = 0  
Selection.setFocus(textAR[textCounter]])

var keyListener:Object = new Object();  
keyListener.onKeyDown = function() {  
if (Key.isDown(Key.TAB)) {  
trace(“the key is TAB!”)  
textCounter++  
if(textCounter \>= textAR.length){  
textCounter = 0  
}  
Selection.setFocus(textAR[textCounter]);  
trace(textAR[textCounter])  
}  
};  
Key.addListener(keyListener);  
[/AS]  
i read about tabIndex somewhere, but cant use that too…

hope someone out there can help me out.  
thanks in advance!
