Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    OK, thank you both, it works. I understood now this capture event method.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •