Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-02-2004, 11:06 AM   PM User | #1
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
how to create new event handlers

It looks like setAttribute() can not create event handlers. Is there any other method to create new event handlers.

I need something like:

document.getElementById('id').setNewEvent('onclick','afunction()')

... while there is no initial such an event handler inside that DIV...

Any ideeas?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 02-02-2004, 11:22 AM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Code:
[object HTMLElement].onevent=function(e){
    e=e||window.event;
    /* Insert your event handler code here.
        The variable e is the event object.
        The target element is e.target in W3C compliant browsers,
        e.srcElement in ie. */
}
Remember that event names should be lowercase.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 02-02-2004, 11:39 AM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
I don't get it... To stop the select scroll onmousewheel I need something like (obviously is aufully worng below)???:

<html>
<head>
<script>
document.getElementsByTagName('select')[0].onmousewheel = function(e){
e=e||window.event;
return false
}
</script>
</head>

<body>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</body>
</html>


(I need it this way, as I have many select objects on page (I'll build an increment for that, but till than I have to understand the method fo a single one...
??
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 02-02-2004, 03:38 PM   PM User | #4
Garadon
Regular Coder

 
Join Date: Jul 2002
Posts: 698
Thanks: 0
Thanked 0 Times in 0 Posts
Garadon is an unknown quantity at this point
You can't access uninterpreted elements, so if you wan't to access an element by javascript u will need to either put the code in a function like I did thats called in the body's onload or put a code block behind the the element.

Code:
 
<html>
<head>
<script>
function block(){
document.getElementsByTagName('select')[0].onmousewheel = function(e){
e=e||window.event;
return false
}}
</script>
</head>

<body onload="block();">
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>

</body>
</html>
Garadon is offline   Reply With Quote
Old 02-03-2004, 08:19 AM   PM User | #5
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
OK, thank you both, it works. I understood now this capture event method.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:57 PM.


Advertisement
Log in to turn off these ads.