By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Recieving Error: 'theForm' is undefined

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.