Hey guys. Im working on a code which has AHAH submit form, which works when the submit button is clicked. Is there a way to trigger tha AHAH Submit using jQuery? Preferbly in a .click() ?

Thanks :)

Comments

darklight’s picture

BUMP anyone?

nienaber’s picture

So I spent a lot of time messing with ahah and node form... painful.
Needless to say I did discover your answer and wanted to share.
If you have a submit button setup as follows:


$form['choice_info']['update_usage'] = array(
    '#type' => 'submit',
    '#value' => t('More choices'),
    '#description' => t("If the amount of boxes above isn't enough, click here to add more choices."),
    '#weight' => 1,
    '#submit' => array('poll_more_choices_submit'), // If no javascript action.
    '#ahah' => array(
      'path' => 'challenge/genre/js',
      'wrapper' => 'genre-info-wrapper',
      'method' => 'replace',
      'effect' => 'fade',
      'event' => 'click',
    ),
  );

The important part here is the 'event' => 'click' once that is in place you can add a simple jQuery to your form:

drupal_add_js('$(document).ready(function() {
    $("#edit-choice-info-platform").change(function() {
	alert("Try and trigger submit");
        $("#edit-choice-info-update-usage").triggerHandler("click");
    });
});', 'inline');

Notice the use of jQuery triggerHandler. In my case what I did was when a select option was changed I would fire the submit button to populate another select options. Using AHAH in a custom node, as part of the select, causes the value chosen in the select to not be posted via AJAX. Three very painful days later. So I guess I am posting this for anyone else wondering.

STINGER_LP’s picture

nienaber, big thank you to you for this! It was really helpful!

hapaheala’s picture

You saved my life. Really... thanks for posting this!!

charlie-s’s picture

Super helpful. Also, here are the default handlers for AHAH events on different form element types: http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.ht...