...

View Full Version : can I tell whether a form is being submitted



nikko50
10-12-2011, 05:31 AM
Hi all!

I have a form called "theForm". How can I tell if the user has submitted the form or hit the submit button??

Is it..


if(document.theForm.onsubmit()){

do something

}else{

}

Old Pedant
10-12-2011, 05:58 AM
<form action="xxxx.yyy" method="post" onsubmit="alert('call any function here'); return true;">

If you want to validate the form, at the same time, do something like


<form action="xxxx.yyy" method="post" onsubmit="return validateForm(this);">

and have validateForm return true if no errors or false for one or more errors.

Kor
10-12-2011, 01:55 PM
You may do it dynamically, as well:


onload=function(){
var form=document.forms['theForm'];
form.onsubmit=function(){
// do something
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum