Sign in to follow this  

[web] Want to make my site accessible

This topic is 4195 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>
		
		<li id="NCB" class="showhide">
			<ul class="level2">
				<li>
				Partnership
				</li>
				<li>
				How does the <acronym title="National Child Benefit">NCB</acronym> work?
				</li>
			</ul>
		</li>

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.

Example:

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

<title>TEST</title>

<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;
}
};

</script>

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

<p>
Press 'n' to toggle visibility.
</p>

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

</body>
</html>


Share this post


Link to post
Share on other sites

This topic is 4195 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this