JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 13th, 2003, 08:22 AM
srishti srishti is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 3 srishti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
IE DOM Event Assignment

Hi,

I am trying to do dynamically assign the action that needs to be performed on click of a 'tr' which has been dynamically created (The div, table, tbody, tr and the td's in it are all dynamically created) and then appended to the body of another frame.

'menu_access_path' is a global variable and 'menu_level' is a local variable which is calculated by the 'level' received by the function when the 'tr' is clicked that needs to be set at each level that is 'event_action' needs to look something like this: parent.show_menu.mouse_over(this, 1); parent.show_menu.create_menu(this, 1);

Now, i am getting this value in the 'event_action' variable and am also able to 'setAttribute' of 'onClick' on Mozilla 1.5 (and everything is working beautifully). BUT when it comes to Internet Explorer 6.0, it fails.

function create_menu(th, level)
{
..
..

menu_level = level +1;
....
...
...

event_action = menu_access_path + 'mouse_over(this, ' + menu_level +');' + menu_access_path +'create_menu(this, ' + menu_level +')';

..
...

CODE FOR MOZILLA 1.5: new_tr_obj.setAttribute('onClick',event_action);
...
..

CODE FOR IE:
new_tr_obj.onclick = event_action;

}

When i see the innerHTML of the page i see that the correct code is written on 'onclick' in IE but nothing happens on 'onclick'. On the otherhand if i use something like this


new_tr_obj.onclick = abcd;


function abcd()
{
event_action = menu_access_path + 'mouse_over(this, ' + menu_level +');' + menu_access_path +'create_menu(this, ' + menu_level +')';

eval(event_action);

}

then 'onclick' works but i DO NOT get a fixed value for each tr, which i wanted to assign, since the value of 'menu_level' just keeps on icreamenting on every click.

PLEASE HELP!!!

Reply With Quote
  #2  
Old January 17th, 2005, 09:36 AM
gerix gerix is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 gerix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile IE DOM Event Assignment solution

I had the same problem, after some search, I find a solution.

In IE, you have to use the fonction attachEvent on the object you want to assign it.

for example: myobject.attachEvent("onclick", functioname)

unfortunatly, you can't give argument to the function (it take pointer), but you have access to an object called "event".

event.srcElement give you a reference on the DOM element which call the event handler.

Good Luck

Gerix

For more information about IE's DOM take a look at http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > IE DOM Event Assignment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway