Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > onclick listbox

Reply
Thread Tools

onclick listbox

 
 
shanneah
Guest
Posts: n/a
 
      12-16-2005
Hi,
I have created a scrollable listbox. When I click on the last element
in the listbox, it calls the appropriate method (Method A) . If I then
use the scroll bar to navigate back to the top of the list, it calls
method A each time I click on the scroll bar. This is because the
onclick event handler is on the entire list box. How do I ensure that
the event handler is only called when I click on the selected element
of the list box? Below is snippets from my code

function displayListBox(){
//Get the listbox
var listbox = document.getElementById('listbox');
addItemToListBox(listbox);
....
listbox.addEventListener("click", handleOnClickEvent, true);
....
}

function addItemToListBox(listbox){
//Create new list item
listItem = document.createElement('listitem');
....
listItem.setAttribute("reacttoclick", "true");
....
listbox.appendChild(listItem);
}

function handleOnClickEvent(e){
var element = e.currentTarget;
var selected = element.selectedItem;
....
}

Thanks in advance for your help.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overriding an onclick with another onclick tomlong@gmail.com Javascript 4 01-26-2006 09:26 PM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM
Re: now desparate! - 1st listbox contents disappears when 2nd listbox appears? blenderdude ASP .Net 0 08-03-2003 10:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57