I have a formblock with an ajax form on my page.

I can click the submit button, and it submits and outputs a message. Great.

How can I get it to submit with javascript.

I've tried:
$(#edit-submit-3).trigger('click');
$(#edit-submit-3).trigger('submit');

Neither of which works. What's the correct way to get the module to submit. Thank you.

Comments

ManyNancy’s picture

Status: Active » Closed (fixed)
kvvnn’s picture

Status: Closed (fixed) » Active

Can you please explain how you made this work?

kvvnn’s picture

Status: Active » Closed (fixed)

I am closing since this is a javascript issue and has nothing to do with Ajax module.

I'm not sure how to make it work.

melchior’s picture

This one drives me crazy.

I've got exactly the same issue triggering a form by javascript when multiple forms are existing.

I also like trigger like ManyNancy with sth like: $(#edit-submit-1).trigger('click');

I found out that the problem lies here (ajax.js):

---------
f.each(function(){
this.ajax_activator = null;
$(this).submit(function(){
alert('submitform');
//console.error ("submit");
if (this.ajax_activator === null) {
alert("nok");
this.ajax_activator = $('#edit-submit', this);
}
if (this.ajax_activator.hasClass('ajax-trigger')) {
alert("ok");
Drupal.Ajax.go($(this), this.ajax_activator);
return false;
}
else {

return true;
}

if (this.ajax_activator === null) {
is always null when using s.click () or s.trigger('onclick');

if only one form exists it works, because the fallback " this.ajax_activator = $('#edit-submit', this); " take place

can anybody help please? I didn't get it :(

thhxx,
melchior

melchior’s picture

Status: Closed (fixed) » Active
ManyNancy’s picture

Sry, no idea tbh. I did a workaround previously, using the clicking on the save button to trigger my other events, but still need this.

melchior’s picture

can you tell me more details about your workaround?

I tried everything thinkable to get it working but failed all time :(

ManyNancy’s picture

All I did was change my node creation workflow to include manually clicking the save button, replacing earlier steps in the workflow.

kvvnn’s picture

melchlor : This is NOT an ajax module issue, but a javascript issue in general.

If you find a solution, please post :D

ManyNancy’s picture

@kevin riggen, wut.

Yes it is an ajax module problem, what are you on? In fact #4 explains why.

kvvnn’s picture

@ManyNancy

(Ignoring your irritating reply to me)

From everything I've tried and researched, the below link sums up what happens when you try and submit a form using javascript:
http://stackoverflow.com/questions/645555/should-jquerys-form-submit-not...

Simply put, any actions that are triggered when the Submit button is clicked by the user DO NOT GO THROUGH when using a javascript submit() or click() event.

Are you saying that this is not true?

Regarding #4, I'm not sure what he meant by "this works when there is only 1 form", as I've tried it with only 1 form in many cases. Have you?

The only solution I know of is to hijack the form's "action" attribute and use a jQuery ajax() call by yourself.

ManyNancy’s picture

That doesn't make it a general js question. Since the submit event is not fired, ajax module should provide us with another event to trigger.

bartclarkson’s picture

Version: 6.x-1.x-dev » 6.x-1.4

I might not have the same use case as others on this thread, but I'm pretty sure it's the same. Here's what I did (having wrapped my ajax form in <div id="palette-form" /> for my own particular ends).

<script type="text/javascript">
Drupal.Ajax.go($('#palette-form #node-form'), $('#palette-form #edit-submit'));
</script>

The first argument is the formObj, the second is the submitter. This allows you to get your hands on the wonderful a_ajaxSubmit() function. See Drupal.Ajax.go @sites/all/modules/ajax/ajax.js; line 83; (v6.x-1.4) for more information.

Shadi.Alian’s picture

thnx for that, and it works without rapping the form
Drupal.Ajax.go($('#node-form'), $('#edit-submit'));

arski’s picture

wow, so nice! thanks so much for that suggestion! was trying to force click() and submit() and was getting some blank page with what appeared to be ajax module's config options in return.. go() works very nicely indeed.

brendoncrawford’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.