views:

356

answers:

2

How can I add a onkeyup event to a custom form field in Drupal 6?

A: 

The Drupal forum threads How do I add an "onblur" javascript event handler to a form field... and jQuery event not firing cover this very topic. In short, you should use jQuery to inject your javascript into the form.

Grayside
A: 

Drupal has the drupal_add_js() function which it uses to add javascript files to a page. This is the first step, after that you will have jQuery available to use, so doing this should work for you just fine.

$(document).ready(function () {
    $("#form-element-id").keyup(function () {
        // Do your things here.
    })
}

You should note that this is more of a javascript/jQuery question than it is a Drupal question. You only need Drupal to add the js file itself, the rest is pure javascript with jQuery

googletorp