Recieving Error: 'theForm' is undefined

N

Nathan Sokalski

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
 
S

Scott M.

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'];
 
B

bruce barker

either the script referencing theForm occurs before the declaration or
form1 is not defined (a form tag with name form1).


-- bruce (sqlwork.com)
 
S

Scott M.

And, remember "Form1" != "form1".



Scott M. said:
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 said:
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
 
G

Guest

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

try

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

Juan T. Llibre

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.





Anon User said:
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

try

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top