Jump to content
  • Advertisement
Sign in to follow this  

[web] Want to make my site accessible

This topic is 4564 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey ladies and gents, I'm working on a website for work and it requires me to make the site accessible. Easy enough but I currently use a javascript to expand/collapse my nav bar. However I'd like to avoid having to use onClick as this isn't completly reliable (accessibility wise) so I figured I could use something like onkeypress. However this is where I'm using it:
<li onClick="showhide('NCB')">
		What is the <acronym title="National Child Benefit">NCB</acronym>?
		<li id="NCB" class="showhide">
			<ul class="level2">
				How does the <acronym title="National Child Benefit">NCB</acronym> work?

As you can see the onClick is inside a li (which is styled with CSS to be a 150px wide box). The onClick works perfectly in IE and FF but I can't get the same functionality with onkeypress or onFocus. Would you folks know a good solution? Thanks PS. If you see something that is horrible wrong (from an accessibility stand point) let me know so I can come up with a fix. The expand/collapse javascript will be arranged so it doesn't keep a user with javascript turned off from seeing it ;-)

Share this post

Link to post
Share on other sites
You need to react to the document.onkeypress event. Th event object passed to this function tells you which key was pressed. In reaction you could toggle the visibility of an element on your page.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
var isHidden = true;

function evtKeyPress(_evt)
var evt = (_evt ? _evt : window.event);
var keyCode = (evt.which ? evt.which : evt.keyCode);
var keyVal = String.fromCharCode(keyCode);

if (keyVal == 'n')
document.getElementById('showHide').style.visibility = (isHidden ? 'visible' : 'hidden');
isHidden = !isHidden;


<body onload="document.onkeypress=evtKeyPress;">

Press 'n' to toggle visibility.

<p id="showHide" style="visibility: hidden;">
<a id="myLink" href="http://www.gamedev.net" target="_blank">Go to GameDev.net</a>


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!