5

I have the following form:
<form name="dealerLocatorForm"method="post"action="result.php">...</form>

I have attached the Omniture SiteCatalyst formAnalyis plugin to it, which is supposed to send back information only when the form was NOT submitted.

The expected behavior: when a form is submitted using a submit button NO beacon should be fired (because things went as expected).

Problem:
The form needed some validation so the developers decided to programmatically submit the form using: document.form.dealerLocatorForm.submit() or document.dealerLocatorForm.submit()

However, when the form is submitted this way, the plugin fires a beacon informing me that the form was not submitted ALTHOUGH IT WAS.

On the other hand if I use jQuery to submit as so: jQuery('form[name=dealerLocatorForm]').submit()
the form is CORRECTLY submitted and the beacon does not fire !

In short jQuery is successfully replicating all the functionalities of a form submit as if it were submitted by a Submit Button while the document.form submit is not.

So my question is: What is the difference between:
document.form.dealerLocatorForm.submit()
document.dealerLocatorForm.submit()
and
jQuery('form[name=dealerLocatorForm]').submit()

It seems as though jQuery is doing something more accurate.

drenocartero
  • 4,941
  • 7
  • 26
  • 26
  • Having the same question. When I tried to bind $("#myform").submit(function(){ //do something; return false;}) it never fires when document.myform.submit() is called from the form – kiev May 05 '11 at 17:58

3 Answers3

2

The behavior of this syntax is non-standard and not consistent across browsers:

document.form.dealerLocatorForm.submit()
document.dealerLocatorForm.submit()

Use getElementById() instead (which is what jQuery uses internally):

document.getElementById("dealerLocatorForm").submit()

Make sure you have the id attribute set on your form element:

<form id="dealerLocatorForm" ... >
Justin M. Keyes
  • 6,679
  • 3
  • 33
  • 60
0

The syntax for submitting the form through javascript is as follows -

document.formName.submit();

In your case you have the formname as dealerLocatorForm

The code you have used to submit form is -

document.form.dealerLocatorForm.submit();

This is wrong as per syntax, it should be as follows -

document.dealerLocatorForm.submit()
Alpesh
  • 5,307
  • 2
  • 19
  • 19
0

I may be wrong but I think that when you submit the form using jquery, it bypasses the other bound events such as onsubmit() tied to the form. Your beacon is probably fired by some sort of validation on submit and that's probably why it's not fired when using jquery

Damp
  • 3,328
  • 20
  • 19
  • acutally maybe im not explaining this well. jQuery is actually replicating the expected behavior of a button better than the document.form submit. I'll re-edit – drenocartero Jan 21 '11 at 18:02