'theForm' is undefined
However, when I do a View Source one of the <script> elements is as follows:
<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>
You will notice that the first line of code in this script element creates
and assigns a value to a variable named "theForm". This code was generated
by ASP.NET, so it SHOULD be correct, and it looks to me like 'theForm' is
defined. I have seen other people post this error before also, but I can't
remember what they said they did to fix it. Any ideas? Thanks.
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/
But it isn't "correct". The error is caused because the script block
will be before the form element appears in the page and so it will be
undefined because it doesn't exist yet.
> and it looks to me like 'theForm' is defined.
If, and only if, a form with the name/id attribute of "form1" exists at
the time that the script executes.
> I have seen other people post this error before also, but I can't
> remember what they said they did to fix it. Any ideas? Thanks.
1) Make sure the script block appears after the element in the page.
2) Better, is to include it in the postback function. Failing that, wrap
it in a function and call it via window.onload
The entire if part that is not in a function is a bad way of writing a
script though. I would be interested to see a scenario where theForm
didn't get defined on the first line but got defined on the second.
Meaning, a browser that didn't support document.forms['form1'] but did
support document.form1
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Because I did not specifically request that this script be added (it gets
added automatically, my code does not include anything that says where to
put the script or even that it should be included at all), what should I do
to fix the problem? Thanks.
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/
"Randy Webb" <HikksNo...@aol.com> wrote in message
news:ybadndl_h4p...@telcove.net...
Stop using ASP.NET :)
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Nathan Sokalski" <njsok...@hotmail.com> wrote in message
news:eQEv$ovqHH...@TK2MSFTNGP05.phx.gbl...
<form id="form1" runat="server">
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/
"Eliyahu Goldin" <REMOVEALLCAPIT...@mMvVpPsS.org> wrote in
message news:%233C402y...@TK2MSFTNGP03.phx.gbl...