Ruudt
Ruudt

Reputation: 262

Mootools submit form only works when selecting form through id

I've been trying to submit a form through mootools (1.4.5) on FF 14. The form does not contain an input named submit (which is often the problem). What I want is onchange in a select to submit the form. After half an hour the code below was my first attempt that got it working. objSelect is a select object that is contained within the form that I need to submit.

$(''+objSelect.getParent('form').get('id')).submit();

.

What the reason that the code below doesn't work as well?

// Without the explicit cast to string (''+); doesn't work
$(objSelect.getParent('form').get('id')).submit();

nor

// Most obvious way; doesn't work
objSelect.getParent('form').submit();

Upvotes: 2

Views: 283

Answers (1)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

you can't have child nodes with reserved names that get exported via old DOM level API - see here how forms are being represented: http://www.quirksmode.org/js/forms.html#access

So basically - at an element level, if you have:

  • form
    • input[name=foo]
    • input[name=bar]

form.foo and form.bar will reference these element on the form element object.

the problem in your case is:

  • form (with a .submit and .reset method)
    • button[name=submit]

now form.submit stops referencing the submit method and starts referencing the input element.

you still submit this form by doing either:

  • rename the element that is wrong or remove from the form.
  • cheat by calling submit from a clean form.

new Element("form").submit.call(this.getParent("form"));

basically you create a new form element with a clean submit method. that returns an object and you call the method with the other "dirty" form as context.

this is just the same as doing

Array.prototype.slice.call(arguments)

Upvotes: 1

Related Questions