2
$form['name'] = array(
        '#type' => 'textfield',
        '#title' => t('Name'),
        '#size' => '27',
        '#inline' => 'true',
        '#required' => TRUE,
        '#prefix' => '<div id="ajax-link">',
        '#suffix' => '</div><div id="ajax-display"></div>',
        '#ajax' => array(
          'effect' => 'fade',
          'callback' => 'ajax_textfield_callback',
          'wrapper' => 'ajax-display',
          'event' => 'onkeypress',   /////////////////Want to add event
        ),
    );

Here in example i have to add event (slashed location). By Default it takes on change event. I want to change that event to onkeypress event.

1

See this link.

You can specify any valid jQuery event.

So, you need to change 'onkeypress' to 'keypress'.

0

By definition from MDN

The onkeypress property sets and returns the onKeyPress event handler code for the current element.

onkeypress is not a event name but a element property for returning the event handler.

The event name should be keypress.

Theoretically, jQuery should be able to handle any JS event name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.