/    Sign up×
Community /Pin to ProfileBookmark

Help regarding onfocus function in javascript

Hi,

I have an horizontal menu using html lists.I want to display the firstlevel and secone level menus when the user uses tab key navigation.I am trying to use onfocus function but it is not working properly…I am posting my horizontal menu structure here…can some one help me with this.

<ul id=”nav”>
<li><a href=”#”>Home</a></li>

<li><a href=”#”>Home2</a>
<ul>

<li><a href=”#”>subitemazxczxcgfhgfhgfhgfh</a>
<ul>
<li><a href=”#”>test 1sdfsd</a></li>
<li><a href=”#”>test 2</a></li>
<li><a href=”#”>test 3</a></li></ul>
</li>
<li><a href=”#”>subitemb</a><ul>

<li><a href=”#”>test 4</a></li>
<li><a href=”#”>test 5</a></li>
</ul>
</li>

</ul>

</li>
<li><a href=”#”>Home3</a>
<ul>
<li><a href=”#”>aubitema1</a></li>
</ul>
</li>
</ul>

Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CuppyTeaNov 28.2008 — [CODE]<ul id="nav">
<li><a href="#">Home</a></li>

<li><a href="#" onfocus="alert('Hello')">Home2</a>
<ul>

<li><a href="#">subitemazxczxcgfhgfhgfhgfh</a>
<ul>
<li><a href="#">test 1sdfsd</a></li>
<li><a href="#">test 2</a></li>
<li><a href="#">test 3</a></li></ul>
</li>
<li><a href="#">subitemb</a><ul>

<li><a href="#">test 4</a></li>
<li><a href="#">test 5</a></li>
</ul>
</li>

</ul>
</li>
<li><a href="#">Home3</a>
<ul>
<li><a href="#">aubitema1</a></li>
</ul>
</li>
</ul>[/CODE]


Works for me...

If your attaching the onfocus event by Javascript..

(i.e. some variation of ... "document.getElementById('navthingy').onfocus = something"), bear in mind that the following will not work...

[CODE] document.getElementById('navthingy').onfocus = alert("hello");[/CODE]

The following is valid syntax...

[CODE]document.getElementById('navthingy').onfocus = function() { alert("hello") }[/CODE]

Hope it helps,
Copy linkTweet thisAlerts:
@santooauthorDec 01.2008 — Hi,

thanks for the reply...but you dint answered my question...actually i want to show the submenus on tabbing on a menu item.

Any help would be greatly appreciated.

thanks.
×

Success!

Help @santoo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...