Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-05-06
Medium Priority
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 34

Expert Comment

by:Big Monty
ID: 35708885
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()">

Expert Comment

ID: 35708887
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

ID: 35709381
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

ID: 35709406
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


Accepted Solution

abhinayp earned 2000 total points
ID: 35720648
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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