How to control tabIndex

Discussion in 'JavaScript' started by venkata_kesava, Sep 14, 2009.

  1. #1
    Hi All,
    I am very new to JavaScript. I have one HTML page which three buttons.I can use tab to move the focus from one button to other button. If user click any of the button i create one dialog. As dialog is there we can not click on any of the button presented in the page. But when user does tab, browser move the focus to the button then user can press the button using space bar. How to avoid movement of focus to go beyond the dialog.

    Please help me to resolve this issue
     
    venkata_kesava, Sep 14, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    you need to trap the onkeydown/up event and then compare the keycode to tab, returning false / stopping event bubbling if it matches a tab. just google it - here is the first thing i found on the serps: http://freecode-freecode.blogspot.com/2007/06/how-to-catch-tab-key-press-with.html (not great but you get the idea)

    note, its much easier with a framework also and more cross browser compliant with the event handling.
     
    Last edited: Sep 14, 2009
    dimitar christoff, Sep 14, 2009 IP
  3. venkata_kesava

    venkata_kesava Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the prompt reply. I have tried this. It can work fine in Firefox as i stop the event bubbling but in case of IE it can not work. Still browser moves the focus to different buttons.

    How to control in IE?
     
    venkata_kesava, Sep 14, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    as I said, each browser has its own idea as to how events need to take place.

    look at this example in mootools (a javascript framework) which rewrites and extends the browser's events so they are always rendering the same results:

    http://mooshell.net/g9nRV/

    the trapped element is 2. All I do here is compare the passed event's key property and then stop the event bubbling in full on tab - note that in IE, a return false is not always with the same effects as a event.preventDefault(); in other browsers.

    coding that kind of thing on your own is like re-inventing the wheel :)
    http://www.mootools.net/docs/core/Native/Event -> look at things you can do with mootools events :)
     
    dimitar christoff, Sep 14, 2009 IP
  5. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    gumape, Sep 15, 2009 IP
  6. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    gumape, Sep 15, 2009 IP