views:

44

answers:

3

Let's say I have a web page with a header menu, when I click the header menu, it calls a servlet that creates the sidebar. Is it possible that without using the document.getElementById? And just simulate keystrokes "tab" and "enter" via javascript so I don't have to click the menu to view the sidebar?

A: 

Could you describe what you want to achieve a bit more?

What I understood is that you want to be able to show ( and may be also hide) the sidebar with the tab button.

You could use the .keypress() function in jQuery - http://api.jquery.com/keypress/

Also check out this tutorial on Nettuts, I think it may be useful for you - http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-keypress-navigation-using-jquery/

var x
Hi, example: instead of clicking the 3rd item in the menu, I want to click it via pressing tab three times then pressing enter.
ASC
A: 

You can use the attribute tabindex on the elements that makes your menu.

eg: <ul tabindex="1">... and set the focus on the first one when opening the page.

They will act as form field when you press tab.

Then for the enter place a single onkeyup listener on a parent node common to all menus items:

menuParent.onkeyup = function(ev){
  var selectedMenu = ev.target || ev.srcElement,
      keycode = ev.keyCode;
      if(keycode === 13){
        //the user pressed enter
      }
  ...
}
Mic
Mess with tabindex at your peril, it can seriously disadvantage unsighted users if changed without a lot of thought. Read this post before doing anything with tabindex: http://www.rnib.org.uk/professionals/webaccessibility/wacblog/Lists/Posts/Post.aspx?id=41
Mark Chorley
@Mark, the tabindex usage described at the link is about forms. Here(from what I understood) is not about input fields, but to allow a keyboard navigation on a menu.
Mic
A: 

You can do what you want using JavaScript, but there's a much easier way to do it than by simulating keystrokes.

I am assuming that what happens when you click the link is that a JavaScript function is called, which causes the submenu to appear. All you need to do is to find out what that function call is (let's say it's called "callTheFunction"), and then call it onload, like this:

<script type="text/javascript">
window.onload=callTheFunction;
</script>

Hopefully that will give you the idea. If you need any more help, please provide a URL or code sample.

Mark Chorley
Hi Mark, I cannot call the javascript because it's in a different domain. We're trying to do a process workaround.
ASC
A different domain? Is the menu in an iframe then, and therefore not part of the DOM? Have you got a URL for this problem?
Mark Chorley