javascript - is there an event that will launch once the user submits the form?

Posted on 2011-05-06
Last Modified: 2012-08-13
I am trying to launch a function once the user submits the form...are there any?

windows.submit function() {} ?
Question by:GlobaLevel
    LVL 32

    Expert Comment

    by:Big Monty
    that would be the onsubmit() function. to fire it once the form is submitted, simply attach it to the form tag:

    <form id="frm" method="post" onsubmit="functinName()">
    LVL 9

    Expert Comment

    Each form has a JavaScript event called onSubmit that is triggered when its submit button is clicked.
    If this even returns 0 or false then the form cannot be submitted, and if it returns 1 or true it was submitted.
    LVL 10

    Author Comment

    Im getting ..Name 'TextArea3' is undeclared....for ALL the textareas...
    window.onload = function () {
         var textA1 =  document.getElementById("<%= attendant_name.ClientID %>").value 
             document.getElementById("<%= txtTextbox2.ClientID %>").innerHTML =  textA1
           textA1 =  document.getElementById("<%= attendant_name1.ClientID %>").value 
             document.getElementById("<%= textarea2.ClientID %>").innerHTML =  textA1
              textA1 =  document.getElementById("<%= attendant_name2.ClientID %>").value 
             document.getElementById("<%= textarea3.ClientID %>").innerHTML =  textA1
             textA1 =  document.getElementById("<%= attendant_name3.ClientID %>").value 
             document.getElementById("<%= textarea4.ClientID %>").innerHTML =  textA1
           textA1 =  document.getElementById("<%= attendant_name4.ClientID %>").value 
             document.getElementById("<%= textarea5.ClientID %>").innerHTML =  textA1

    Open in new window

    LVL 10

    Author Comment

    see attached..
    Im using hiddenfields...
       <asp:HiddenField runat="server" ID="attendant_name" />     
        <asp:HiddenField runat="server" ID="attendant_name1" />
        <asp:HiddenField runat="server" ID="attendant_name2" />
        <asp:HiddenField runat="server" ID="attendant_name3" />
        <asp:HiddenField runat="server" ID="attendant_name4" />
            attendant_name.Value = Session("SessionTA1").ToString()
                attendant_name1.Value = Session("SessionTA2").ToString()
                attendant_name2.Value = Session("SessionTA3").ToString()
                attendant_name3.Value = Session("SessionTA4").ToString()
                attendant_name4.Value = Session("SessionTA5").ToString()
    code behind...
      <WebMethod()> _
       Public Shared Sub SetVariable(ByVal ta1 As [String], ByVal ta2 As [String], ByVal ta3 As [String], ByVal ta4 As [String], ByVal ta5 As [String])
            HttpContext.Current.Session("SessionTA1") = ta1
            HttpContext.Current.Session("SessionTA2") = ta2
            HttpContext.Current.Session("SessionTA3") = ta3
            HttpContext.Current.Session("SessionTA4") = ta4
            HttpContext.Current.Session("SessionTA5") = ta5
        End Sub
     function setSession()  { 
                  var ta1 =  document.getElementById('<%=txtTextbox2.ClientID%>').value
                    var ta2 =  document.getElementById('<%=TextArea2.ClientID%>').value
                      var ta3 =  document.getElementById('<%=TextArea3.ClientID%>').value
                        var ta4 =  document.getElementById('<%=TextArea4.ClientID%>').value
                          var ta5 =  document.getElementById('<%=TextArea5.ClientID%>').value
            PageMethods.SetVariable(ta1, ta2, ta3, ta4, ta5);

    Open in new window

    LVL 4

    Accepted Solution

    Here is a sample app i just created which can get u going with.
    *********** aspx ***********
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
            function SampleFunction() {
                var txt = document.getElementById('<%= txtBox1.ClientID %>');
                if (txt.value == "")
        <form id="form1" runat="server">
            <asp:TextBox runat="server" ID="txtBox1">
            <asp:Button ID="Button1" runat="server" Text="Click Me" />
    ********** C# Code behind **********
    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    public partial class _Default : System.Web.UI.Page 
        protected void Page_Load(object sender, EventArgs e)
            ClientScript.RegisterStartupScript(this.GetType(), "test", "SampleFunction();", true);

    Open in new window


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now