Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: how can i tell when document.links loses focus?


Message #1 by "fredd rae" <fredd@l...> on Thu, 6 Sep 2001 15:03:06
hello,
sorry for newbie question. trying to produce a function that allows users 
to use the space bar to tab through the links on a page in a loop. it 
works as it is (by adding an onBlur to the last link on the page), but i'm 
wondering if there's a more efficient method that i can use without 
leaving the function itself and needing to put stuff into the html. 

i don't know how to find out what on the page currently has the focus 
which might be where i'm going wrong? the page is at 
http://www.l0unge.com/tab_test.htm if me pasting this code doesn't work...

<!doctype html public "-//w3c//dtd html 3.2 final//en">
<html>
<head>
<script language="javascript">

	function keydown(e) {
		if (event.keyCode = 32) event.keyCode = 9;
	}

	document.onkeydown = keydown

</script>

</head>
<body link="#800000" alink="#ff00ff" background="?" onload="document.links
[0].focus()">

<p><a href="http://www.l0unge.com">link 1</a></p>
<p><a href="http://www.l0unge.com">link 2</a></p>
<p><a href="http://www.l0unge.com" onBlur="document.links[0].focus()">link 
3</a></p>

</body>
</html>

was looking for something like the below, maybe without having to use an 
incrementing var? 

	function keydown(e) {
		if (event.keyCode = 32) { event.keyCode = 9; }
		// if (focus() isn't within document.links.index)
document.links[0].focus() 
	}

am stumped :( any help would be much appreciated. 



  Return to Index