By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,567 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,567 IT Pros & Developers. It's quick & easy.

Tracking form submit...

P: n/a
Hi,

In Firefox, what's the best way of tracking the form submit?
The following are two ways I tried, but they won't work if the form is
submitted through JavaScript.

Method 1: using the window.onsubmit event handler

Code: window.onsubmit=handleEvent;

Method 2: I am attachin event listeners to all the forms for the event
submit.

Code:

for(var i=0;i<forms.length;i++)
{
var form=forms[i];
form.addEventListener("submit",handleEvent,false);
}

It seems submit event is not generated if the form doesn't have a
submit button. Why so?

What's the best way through which what ever way the form is submitted,
I should be able to track it.

Thanks & Regards,
Rajendra Prasad Murakonda
http://prodizy.livejournal.com/

Aug 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Add an event handler to the form tag like this.
<form name="aform" action="a/place.cgi" method="POST"
onsubmit="handleEvent()">
The submit button triggers the onsubmit handler because that's how you
submit a form. This does not trigger the handler:

document.forms[0].submit();

but you could do this

document.forms[0].submit();
handlerEvent();
prodizy wrote:
Hi,

In Firefox, what's the best way of tracking the form submit?
The following are two ways I tried, but they won't work if the form is
submitted through JavaScript.

Method 1: using the window.onsubmit event handler

Code: window.onsubmit=handleEvent;

Method 2: I am attachin event listeners to all the forms for the event
submit.

Code:

for(var i=0;i<forms.length;i++)
{
var form=forms[i];
form.addEventListener("submit",handleEvent,false);
}

It seems submit event is not generated if the form doesn't have a
submit button. Why so?

What's the best way through which what ever way the form is submitted,
I should be able to track it.

Thanks & Regards,
Rajendra Prasad Murakonda
http://prodizy.livejournal.com/
Aug 31 '06 #2

P: n/a
Benjamin wrote:
Add an event handler to the form tag like this.
<form name="aform" action="a/place.cgi" method="POST"
onsubmit="handleEvent()">
The submit button triggers the onsubmit handler because that's how you
submit a form. This does not trigger the handler:
document.forms[0].submit();
Why is it like that, any idea?
but you could do this
document.forms[0].submit();
handlerEvent();
I am doing it from my firefox extension, and, not to my own web pages.
So whatever I do, I have to do it using a script. AFAIK, the above is
not possible.

Thanks & Regards,
Rajendra Prasad Murakonda.

Sep 1 '06 #3

P: n/a
prodizy wrote:
Benjamin wrote:
Add an event handler to the form tag like this.
<form name="aform" action="a/place.cgi" method="POST"
onsubmit="handleEvent()">
The submit button triggers the onsubmit handler because that's how you
submit a form. This does not trigger the handler:
document.forms[0].submit();

Why is it like that, any idea?
but you could do this
document.forms[0].submit();
handlerEvent();

I am doing it from my firefox extension, and, not to my own web pages.
I guess you mean Greasemonkey. :-)
So whatever I do, I have to do it using a script. AFAIK, the above is
not possible.
Add a button to the form (which by default is a submit button) and call
its click method:

var s = document.createElement('button');
document.someForm.appendChild(s);
s.click();
--
Rob

Sep 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.