473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Recieving Error: 'theForm' is undefined

I have an ASP.NET application which is giving the following JavaScript
error:

'theForm' is undefined

However, when I did a View Source I noticed that ASP.NET added the following
code:

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

I was told in a previous posting that the reason for the error is that the
script containing the declaration and assigning of a value to it occur
before the

--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jun 11 '07 #1
6 3032
If the page does not have a form named "form1", then the variable
declaration will fail and the variable "theForm" won't be able to be
created.
var theForm = document.forms['form1'];
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
>I have an ASP.NET application which is giving the following JavaScript
error:

'theForm' is undefined

However, when I did a View Source I noticed that ASP.NET added the
following code:

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

I was told in a previous posting that the reason for the error is that the
script containing the declaration and assigning of a value to it occur
before the

--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Jun 11 '07 #2
either the script referencing theForm occurs before the declaration or
form1 is not defined (a form tag with name form1).
-- bruce (sqlwork.com)
Nathan Sokalski wrote:
I have an ASP.NET application which is giving the following JavaScript
error:

'theForm' is undefined

However, when I did a View Source I noticed that ASP.NET added the following
code:

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

I was told in a previous posting that the reason for the error is that the
script containing the declaration and assigning of a value to it occur
before the
Jun 11 '07 #3
And, remember "Form1" != "form1".

"Scott M." <s-***@nospam.nospamwrote in message
news:Om**************@TK2MSFTNGP06.phx.gbl...
If the page does not have a form named "form1", then the variable
declaration will fail and the variable "theForm" won't be able to be
created.
var theForm = document.forms['form1'];
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
>>I have an ASP.NET application which is giving the following JavaScript
error:

'theForm' is undefined

However, when I did a View Source I noticed that ASP.NET added the
following code:

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

I was told in a previous posting that the reason for the error is that
the script containing the declaration and assigning of a value to it
occur before the

--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Jun 11 '07 #4
On Jun 11, 2:24 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I have an ASP.NET application which is giving the following JavaScript
error:

'theForm' is undefined

However, when I did a View Source I noticed that ASP.NET added the following
code:

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;}

function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}}

// -->
</script>

I was told in a previous posting that the reason for the error is that the
script containing the declaration and assigning of a value to it occur
before the

--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/
try

var theForm = document.getElementById("form1");

Jun 11 '07 #5
He can't try that, Alexei, because the code is being injected by ASP.NET.

He can't change the embedded javascript funtions, if he's using ASP.NET 2.0.
There's a chance he mioght be able to do that, if he's using ASP.NET 1.1.

All he'd have to do is edit the scripts located in
\wwwroot\aspnet_client\system_web\1_1_4322.

The problem doesn't seem to be that the function is buggy, though.

If Nathan were to rename the page's form to "form2",
instead of naming it "form1", he should see this :

<script type="text/javascript">
<!--
var theForm = document.forms['form2'];
if (!theForm) {
theForm = document.form2;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

Notice that the source reveals that the script has picked up the form's new name.

If that doesn't show up, and the error persists, it's a timing problem.
The javascript is running before the form has been rendered.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
On Jun 11, 2:24 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
>I have an ASP.NET application which is giving the following JavaScript
error:

'theForm' is undefined

However, when I did a View Source I noticed that ASP.NET added the following
code:

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;}

function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}}

// -->
</script>

I was told in a previous posting that the reason for the error is that the
script containing the declaration and assigning of a value to it occur
before the

--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/

try

var theForm = document.getElementById("form1");

Jun 11 '07 #6
On Jun 11, 3:01 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
He can't try that, Alexei, because the code is being injected by ASP.NET.
On Jun 11, 2:24 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
However, when I did a View Source I noticed that ASP.NET added the following
code:
Okay, I see. Sorry!

Jun 11 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
2
by: Paul Ten-Bokum | last post by:
Hi When I submit data from a dropdown in a form, it works fine except on macs when the value is a zero. It then submits values like "NsNu" or "H?vH?vR?y". I can't find a solution and searching...
2
by: SmittyBroham | last post by:
Hello, I have a function that loops through 2 select lists and records the values of any hi-lighted options a user would have selected. It then sets 2 corresponding "hidden" form elements to the...
0
by: Thomas Lin | last post by:
With smart navigation turned on (either in the web.config or the page directive), I'm getting a javascript error on a lot of pages on my website. The error is "Illegal Assignment". function...
0
by: Coco | last post by:
i have the following java script error after installing framework 1.1 RunTime error Line 54 Error:Expected ; i knew there's a hot fix available but i can't obtain it is there anyway i can...
0
by: William D. Sossamon | last post by:
http://support.microsoft.com/default.aspx?kbid=818803 1.. You add the following form to a user control: <form id="Form1" name="Form1" runat="server">2.. You add the user control, for example,...
14
by: Rich | last post by:
I am converting my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 (.NET v2.0.50727). The entire solution uses serveral technologies - Windows Server 2003 (AD, SQL Server 2000, IIS,...
3
by: jason | last post by:
I have a very simple asp.net 2.0 page with one textbox that onkeyPress is suppose to do some check of what was typed. Below is the source showing the javascript function is available. The minute I...
5
by: Nathan Sokalski | last post by:
I have an ASP.NET application which is giving the following JavaScript error: 'theForm' is undefined However, when I do a View Source one of the <scriptelements is as follows: <script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.