SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict y_oda2002's Avatar
    Join Date
    May 2005
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding Events To Input Items

    Hi everyone,

    I am new to using dhtml and was wondering when you create an input element, i.e.
    Code:
    var someInput = createElement('input');
    How do you add an event to an input item?
    like a onKeyUp event.


    Thanks,

    Nick
    Nicholas Rhodes
    Asgard Development
    http://www.asgard-dev.com

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are multiple ways. The simplest is to use DOM0 events.
    Code:
    var someInput = document.createElement('input');
    someInput.onkeyup = function(e){
      e = e||window.event;
      var key = e.which||e.charCode||e.keyCode;
      alert(key);
    }
    For more information, check these out:
    http://www.quirksmode.org/js/contents.html#events
    http://www.brainjar.com/dhtml/events/
    http://developer.apple.com/internet/...entmodels.html
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

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