Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    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{
    
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You may do it dynamically, as well:
    Code:
    onload=function(){
    var form=document.forms['theForm'];
    form.onsubmit=function(){
    // do something
    }
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •