Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hii..i hav simple problem in javascript

Status
Not open for further replies.

sonyerricsonk750i

Programmer
Aug 24, 2007
12
0
0
IN

hiii
im new in javascripting world

i am doin a simple program

<html>
<head>
</head>
<body>
<a href="test41_1.html">test41_1
<br><a href="test41_2.html">test 41_2
<br><a href="test41_3.html">test 41_3
<br><a href="test41_4.html">test 41_4
<br><a href="test41_5.html">test 41_5
</body>
</html>

the output of it is
test41_1.html
test41_2.html
test41_3.html
test41_4.html

now problem is this that
using the TAB key i can navigate in this links
but,
i want to use DOWN arroy key also for navigating thro links with TABs.

do anyone knows hoe to perform such programme?

thnx alott

S
 
Hi

Am I rude if I say that your requirement is stupid ? Anyway, this works in Mozillas, Opera, Safari and Explorer.
Code:
<html>
<head>
<script type="text/javascript">
var al=undefined
window.onload=function() {
  al=document.getElementsByTagName('a')
  for (var i=0;i<al.length;i++) al[i].onkeydown=go
}
function go(e)
{
  e=e?e:window.event
  var key=e.keyCode!=undefined?e.keyCode:e.which
  var obj=e.target!=undefined?e.target:e.srcElement
  if (!al || !key || !obj) return
  if (key!=38 && key!=40) return
  var dir=key==38?-1:1
  var pos=-1
  for (var i=0;i<al.length;i++) if (al[i]==obj) pos=i
  if (pos==-1) return
  al[(pos+al.length+dir)%al.length].focus()
}
</script>
</head>
<body>
<a href="test41_1.html">test41_1</a>
<br><a href="test41_2.html">test 41_2</a>
<br><a href="test41_3.html">test 41_3</a>
<br><a href="test41_4.html">test 41_4</a>
<br><a href="test41_5.html">test 41_5</a>
</body>
</html>
By the way, please learn more about HTML. Preferably before going forward to JavaScript.

Feherke.
 
but my problem realates to lest n right arrows as well.

after clicking on left arrow the tree head should be selected.
let us say
test41_1
test41_1.1
test41_1.2
test41_1.3
test41_2
test41_2.1
test41_2.2
test41_2.3
test41_3
test41_3.1
test41_4
test41_5
test41_5.1
test41_5.2
test41_5.3

then
when i wl b at child say test41_5.2,
by LEFT key,it should directly come at test41_5.
and vice-versa at Right key.

can u please help?

S
 
Hi

[ul]
[li]Put the links into an unordered list.[/li]
[li]When right arrow is pressed, check if the node has a list item child, if has then focus it.[/li]
[li]When left arrow is pressed, check if the node has a list item parent, if has then focus it.[/li]
[/ul]

Feherke.
 

yes i got that already
but
how to find that
if the node has a list item child,
if the node has a list item parent?

thats the main question...
 
Hi

First of all, all those were answered before.

The DOM ( Document Object Model ) describes the structure and the ways to parse the structure of a document.

See the [tt]childNodes[/tt] and [tt]parentNode[/tt] properties of the elements. For simplicity you may want to use [tt]getElementsByTagName()[/tt] instead of [tt]childNodes[/tt], but the [tt]parentNode[/tt] you will have to use recursively.

Feherke.
 

if i use
x.parentNode
in the same javascript,then also its not giving me the parent node?
then
what is th possible way to implement?
 
Hi

[tt]parentNode[/tt] will give you the element's parent. But as I wrote, you will have to use it recursively. For example in the below sample you can see that the [tt]a[/tt] "test41_5.2"'s parent is the [tt]li[/tt], who's parent is the [tt]ul[/tt].
Code:
<ul>
[gray]...[/gray]
  <li><a href="test41_5">test41_5</a>
  <ul>
    <li><a href="test41_5.2">test41_5.2</a></li>
    [gray]...[/gray]
  </ul>
  </li>
[gray]...[/gray]
</ul>

Feherke.
 
thnx for ur quick replies
but
i hav already done by same way
my question of pickin wid parents with association wid LEFT and RIGHT keys is yet beyond eye site.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top