473,322 Members | 1,425 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,322 software developers and data experts.

'document' undefined error

dd
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly
I've been searching for the answer for two hours and I decided to
finally post this question. I'm trying to take a javascript and make
it work with asp. Any thought, ideas or pointers in the right
direction would be greatly appreciated.

I am getting the following error:

Microsoft JScript runtime error '800a1391'

'document' is undefined

/anylink.asp, line 77

which is this line of code: var ie4=document.all

I do not have any forms in this document. I do not understand this
error at all. Here's the full code:

<%
var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
myConnect += Server.MapPath("\\");
myConnect += "\\database\\db.mdb;";

var ConnectObj = Server.CreateObject("ADODB.Connection");
var RS = Server.CreateObject("ADODB.Recordset");
var sql="SELECT gallery_catid,gallery_cat_name from gallery_cat;";

ConnectObj.Open (myConnect);
RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockRea dOnly,adCmdText);
var menu1=new Array();
i=0
while (!RS.EOF)
{
menu1[i]="<a href='?galleryid=" +RS("gallery_catid")+ "'>"
+RS("gallery_cat_name") +"</a><br>";
i=i+1
RS.MoveNext();
}
RS.Close();
ConnectObj.Close();
RS = null;
ConnectObj = null;

var menuwidth='165px' //default menu width
var menubgcolor='lightyellow' //menu bgcolor
var disappeardelay=250 //menu disappear speed onMouseout (in
miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed
var ie4=document.all&&navigator.userAgent.indexOf("Ope ra")==-1;
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv"
style="visibility:hidden;width:'+menuwidth+';backg round-color:'+menubgcolor+'"
onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft :
totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}
function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")?
document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera?
iecompattest().scrollLeft+iecompattest().clientWid th-15 :
window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop :
window.pageYOffset
var windowedge=ie4 && !window.opera?
iecompattest().scrollTop+iecompattest().clientHeig ht-15 :
window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeigh t
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHe ight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good
either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}

function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById?
document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj,
"rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj,
"bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&&
!contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu
%>

You should be able to mouseover this link and have a dropdown of
categories.

<a href="default.htm" onClick="return clickreturnvalue()"
onMouseover="dropdownmenu(this, event, menu1, '150px')"
onMouseout="delayhidemenu()">Web Design</a>

Many thanks in advance for your thoughts.

Jan 17 '06 #1
7 16238
wrote on 17 jan 2006 in microsoft.public.inetserver.asp.general:
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly
I've been searching for the answer for two hours and I decided to
finally post this question. I'm trying to take a javascript and make
it work with asp. Any thought, ideas or pointers in the right
direction would be greatly appreciated.

I am getting the following error:

Microsoft JScript runtime error '800a1391'

'document' is undefined

/anylink.asp, line 77

which is this line of code: var ie4=document.all


document is valid in clientside j[ava]script, not serverside.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 17 '06 #2
Thanks. So since I know so little about javascript, how do I fix it?
Thanks again.

Jan 17 '06 #3
debbie wrote on 17 jan 2006 in microsoft.public.inetserver.asp.general:
Thanks. So since I know so little about javascript, how do I fix it?


Please quote what you are replying to.

This is usenet, not email.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 17 '06 #4

Evertjan. wrote:
debbie wrote on 17 jan 2006 in microsoft.public.inetserver.asp.general:
Thanks. So since I know so little about javascript, how do I fix it?


Please quote what you are replying to.

This is usenet, not email.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


I've never had so much trouble trying to get an answer to anything in
my life. Or replying to a message. Many thanks for your time and
trouble. You gave me a teeny, tiny hint, so I'll run with that and
figure it out. Thanks again.

Jan 17 '06 #5
dd@clickfocal.com wrote:
Hello all. First, I'm a newbie to javascript but not to ASP.
Secondly I've been searching for the answer for two hours and I
decided to finally post this question. I'm trying to take a
javascript and make it work with asp. Any thought, ideas or pointers
in the right direction would be greatly appreciated.

I am getting the following error:

Microsoft JScript runtime error '800a1391'

'document' is undefined

/anylink.asp, line 77

which is this line of code: var ie4=document.all


You cannot directly work with DOM/DHTML objects (document, window, body,
etc.) in server-side script: these objects are only available to client-side
script after the page is loaded in the browser. All you can do with
server-side code is use response.write to modify the html that is sent to
the client . I do not have time to plow through your code to see what you
are attempting to do, but I will suggest that you separate out the logic
that needs to work with client-side objects and put that code into
client-side script blocks. You can use response.write to pass server-side
values into client-side variables like this:

<%@ Language=JavaScript%>
<%
//anything between <%..%> is server-side, ASP code
var s="some value"
%>
<html>
<head>
<script type="text/javascript">
//this is client-side code - <%= is shorthand for response.write
var s="<%=s%>";
alert(s);
</script>

For further help, post to a client-side newsgroup such as
microsoft.public.scripting.jscript or comp.lang.javascript
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 17 '06 #6
debbie wrote on 17 jan 2006 in microsoft.public.inetserver.asp.general:
Evertjan. wrote:
debbie wrote on 17 jan 2006 in
microsoft.public.inetserver.asp.general:
> Thanks. So since I know so little about javascript, how do I fix
> it?


Please quote what you are replying to.

This is usenet, not email.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of
the article headers.


I've never had so much trouble trying to get an answer to anything in
my life. Or replying to a message. Many thanks for your time and
trouble. You gave me a teeny, tiny hint, so I'll run with that and
figure it out. Thanks again.


This is better.

Usenet is not a paid answering service, and many are reading the
postings. So, if you want the total of knowledge work for you, you should
enable those to read according to Usenet-netiquette, and they will
comment on the conversation if they feel rightly compelled [or simply
meddlesome].

================================================== ====

Back to your OQ [original question].

ASP-platform code [can be VBscript or Jscript] is executed on the server
and the resulting HTML code is sent as a HTML file [even though the
extention is still .asp, it is not the original asp-file] to the client
browser.

Code between <% and %>, a way of delimiting the asp vbs or js code, is
NOT sent to the client as such.

"document" or really "window.document" is part [an object] of the DOM
where the browser builds the screen display from the received html code
[that can contain clientside jscript, clientside javascript (or for IE
clientside vbscript)

This DOM is only built in the browser, so is not available to the
serverside code parser/interpreter.

So your code is programmed on a misconception that cannot just be
repaired, but should be redone from scratch.

Examples:

=============

clientside javascript:

<script type='text/javascript'>
document.write('Hello world<br>');
</script>

writes "Hello world" on the screen.

==========

serverside ASP-jscript:

<%
response.write('Helloworld<br>');
%>

sends "Hello world" into the HTML code string that is sent to the client
browser to be processed depending on the code context.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 17 '06 #7
Thanks Bob. That explains much and is very helpful. I was hesitant to
post to a javascript forum since this was an ASP issue, then I was
afraid I'd get chastised for posting to two forums, so I guess I picked
the wrong one afterall :) Many thanks, though for your thoughts.

Bob Barrows [MVP] wrote:
dd@clickfocal.com wrote:
Hello all. First, I'm a newbie to javascript but not to ASP.
Secondly I've been searching for the answer for two hours and I
decided to finally post this question. I'm trying to take a
javascript and make it work with asp. Any thought, ideas or pointers
in the right direction would be greatly appreciated.

I am getting the following error:

Microsoft JScript runtime error '800a1391'

'document' is undefined

/anylink.asp, line 77

which is this line of code: var ie4=document.all


You cannot directly work with DOM/DHTML objects (document, window, body,
etc.) in server-side script: these objects are only available to client-side
script after the page is loaded in the browser. All you can do with
server-side code is use response.write to modify the html that is sent to
the client . I do not have time to plow through your code to see what you
are attempting to do, but I will suggest that you separate out the logic
that needs to work with client-side objects and put that code into
client-side script blocks. You can use response.write to pass server-side
values into client-side variables like this:

<%@ Language=JavaScript%>
<%
//anything between <%..%> is server-side, ASP code
var s="some value"
%>
<html>
<head>
<script type="text/javascript">
//this is client-side code - <%= is shorthand for response.write
var s="<%=s%>";
alert(s);
</script>

For further help, post to a client-side newsgroup such as
microsoft.public.scripting.jscript or comp.lang.javascript
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Jan 17 '06 #8

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

Similar topics

2
by: KathyB | last post by:
Hi, I'm trying to get the following script to work, but I'm getting an error saying "rowID is undefined". function showhide(rowId) { var showRow = "Edit_" + rowID var hideRow = "View_" + rowID...
1
by: rked | last post by:
function validField() //this is to be sure something is in subject { if (document.formDoubleMenuDMA.strSubject.value == "") { nameSPAN1.innerHTML = "Please select a subject";...
1
by: preet | last post by:
On first execution of StartSurf() the siteloc returns undefined On second excution and after that there is no problem. StartSurf is called from a button press, which becomes invisible for 30...
1
by: pbd22 | last post by:
Hi - I have code that automatically fills tabs on a page. In some cases, a URL path won't be correct (the folder and files don't exist) and, in these cases, I want to catch these exceptions and...
2
by: vozzek | last post by:
Hi all, Quick problem here: I have a form containing zero to five drop-down label selections (option_a, option_b, etc...) depending upon what's pulled from my SQL database. So in short,...
3
by: Alexio | last post by:
I need to apply an onLoad() event to call the function displayed below. I tried <body bgcolor="#B3FFB3" onLoad="display(obj)"> and it comes up with an error message of obj undefined. My question is...
6
by: SunshineInTheRain | last post by:
can anyone please help me on problem of 'Sys' is undefined error? I know a lot forum has discussed about this, but none i success to solve the error. I have run it on Window server 2000, IIS 5,...
16
by: manutd7 | last post by:
Hi, Every time I try to access the contents of the following array it returns that it is undefined. I have tried multiple variations on accessing the arrays syntax wise but get different errors...
3
by: Jen O | last post by:
<script> window.onload=myday; function myday(){ var day=new Array("sunday","monday","tuesday","wednesday","thursday","friday","saturday"); var d=new Date();...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.