|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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!!! |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > IE DOM Event Assignment |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|