Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-12-2011, 04:31 AM   PM User | #1
nikko50
Regular Coder

 
Join Date: May 2004
Posts: 375
Thanks: 62
Thanked 0 Times in 0 Posts
nikko50 is an unknown quantity at this point
can I tell whether a form is being submitted

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..

Code:
if(document.theForm.onsubmit()){

do something

}else{

}
nikko50 is offline   Reply With Quote
Old 10-12-2011, 04:58 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
<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
Code:
<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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-12-2011, 12:55 PM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
You may do it dynamically, as well:
Code:
onload=function(){
var form=document.forms['theForm'];
form.onsubmit=function(){
// do something
}
}
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:36 PM.


Advertisement
Log in to turn off these ads.