Tracking form submit...

P

prodizy

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;
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/
 
B

Benjamin

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();
 
P

prodizy

Benjamin said:
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.
 
R

RobG

prodizy said:
Benjamin said:
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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top