Solved

'document' is undefined?

Posted on 2001-08-08
24
918 Views
Last Modified: 2012-08-14
Hello,

     I'm getting the following error with a JavaScript function I'm using:

----------------------------------------------------------

Microsoft JScript runtime error '800a1391'
'document' is undefined
pe/verify.asp, line 24

----------------------------------------------------------

     The following function is the one that's causing the error and is on line 24.  Frankly, I have no idea why the error's appearing.  I thought the document object was automatically included in JavaScript?  Here's the function:

----------------------------------------------------------

<SCRIPT LANGUAGE="JScript" runat=server>

     function SendInfo()
     {
          document.frmMain.submit();
     }

</SCRIPT>

----------------------------------------------------------

     Note that this is being used along with VBScript in an ASP page, so it's already determined with VBScript whether the form should be submitted or not.  This is a predefined, read-only, hidden form that is used only to send information between pages.  I'm open to any suggestions, I'm on a deadline with this project.

     Thanks in advance.

0
Comment
Question by:programming_novice
  • 11
  • 9
  • 2
  • +2
24 Comments
 
LVL 3

Expert Comment

by:nzjonboy
ID: 6366715
programming_novice

try replacing document.frmMain.submit(); with document.forms[0].submit();

nzjonboy
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6366748
Why you want the following 'runat=server'. This may be the cause of the problem. 'runat=server' means you want the script to run at the server.

Try this :


<SCRIPT LANGUAGE="JavaScript">

    function SendInfo()
    {
         document.frmMain.submit();
    }

</SCRIPT>

0
 

Author Comment

by:programming_novice
ID: 6366760
Well, I tried nzjonboy's solution, and the same error showed up, unfortunately.

With nimaig's solution, the error mentioned above didn't appear, but it said that the variable SendInfo() was undefined.  That's why I need it to run on the server, so that VBScript and ASP (which runs on the server) can access it.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6366770
I don't think you can access the document object using Server side JavaScript.

Can you be bit more descriptive why you want the SendInfo()  to be in Server side.
0
 

Author Comment

by:programming_novice
ID: 6366774
I need SendInfo to be on the Server side because that's the only way VBScript (which is server-side in an ASP page) can access it.

However, if anyone can think of any alternatives, I'd be glad to hear them.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6366785
Why you want VBScript to access this method. Can you please explain the scenerio.
0
 
LVL 3

Expert Comment

by:nzjonboy
ID: 6366790
>it said that the variable SendInfo()
was undefined

how are you calling the SendInfo function?

if you are calling it along these lines

sendInf = SendInfo()

then perhaps you could try putting a return true; statement after the submit.

nzjonboy
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6366827
If I am not mistaken, you want the form to be submitted as soon as the page gets loaded. If so
   you can do something like this.
   <HTML>
   <HEAD>
   <SCRIPT LANGUAGE="JScript" runat=server>
     <!--
         function SendInfo(){
              document.frmMain.submit();
         }
     //-->
     </SCRIPT>
     </HEAD>
    <body onLoad="SendInfo()">
         <form name="frmmain">
         </form>
    </body>
    </head>
   
    If you want conditional submit, you can modify the SendInfo something like this
    function SendInfo(){
         <% if form has to be submitted { %>
                 document.frmMain.submit();
           <% } %>
    }
0
 

Author Comment

by:programming_novice
ID: 6368459
nimaig, I tried your method, but instead of using the VBScript inside the JScript, I just used JScript to carry out the conditional program flow.  However, now I always get the error that's supposed to come up when the form isn't supposed to be sent, even if it is.  Any ideas?

BTW, I've increased the points to 150.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6368491
Can you post your code please ...
0
 

Author Comment

by:programming_novice
ID: 6368642
<SCRIPT LANGUAGE="JScript" runat=server>

     function Reset()
     {
          top.location.href = "default.asp";
     }
     
     function SendInfo()
     {
          var strUID = Request.Form("username");
          var strPass = Request.Form("password");
         
          var strRita = perRita;
          var strRitaPass = perRitaPass;
          var strAdmin = perAdmin;
          var strAdminPass = perAdminPass;
         
          switch (strUID)
          {
               case strRita:
                    if (strPass = strRitaPass)
                    {
                         document.frmMain.submit();
                    }
                    else
                    {
                         Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                    }
                   
               case strAdmin:
                    if (strPass = strAdminPass)
                    {
                         document.frmMain.submit();
                    }
                    else
                    {
                         Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                    }
                   
               default:
                    Response.Write("Error:  You have entered an incorrect user name and/or password.  Please go back and try again.");
                   
          }
         
          return true;
     }
     

</SCRIPT>

</HEAD>
<BODY onLoad="SendInfo()">
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6368764
Try something like this. I don't have server to run server side JavaScript/JScript so I haven't tested the code.



<SCRIPT LANGUAGE="JScript" runat=server>

    function Reset()
    {
         Response.Write("top.location.href = 'default.asp');
    }
   
    var strUID = Request.Form("username");
    var strPass = Request.Form("password");
       
    var strRita = perRita;
    var strRitaPass = perRitaPass;
    var strAdmin = perAdmin;
    var strAdminPass = perAdminPass;
    var submitFlag = true;
         
    switch (strUID)
    {
              case strRita:
                   if (strPass = strRitaPass)
                   {
                        submitFlag = true;
                   }
                   else
                   {
                        Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                        submitFlag = false;
                   }
                   
              case strAdmin:
                   if (strPass = strAdminPass)
                   {
                        submitFlag = true;
                   }
                   else
                   {
                        Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                        submitFlag = false;
                   }
                   
              default:
                   Response.Write("Error:  You have entered an incorrect user name and/or password.  Please go back and try again.");
                   submitFlag = false;
                   
    }
   
    if(submitFlag){
         Response.Write("<SCRIPT language='JavaScript'>function SubmitForm(){ document.frmMain.submit(); } </SCRIPT>");
    }else{
         Response.Write("<SCRIPT language='JavaScript'>function SubmitForm(){ } </SCRIPT>");
    }
</SCRIPT>

</HEAD>
<BODY onLoad="SubmitForm()">
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:programming_novice
ID: 6369032
OK, sorry to be a bother, but now I get a different error:

"Active Server Pages error 'ASP 0138'

Nested Script Block

/pe/verify.asp, line 31

A script block cannot be placed inside another script block. "

This error is on the "if(submitFlag)" line with writing the script tags inside the Response.Write.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6371164
Try this :


<HTML>
<HEAD>
</HEAD>
<SCRIPT LANGUAGE="JScript" runat=server>

   function Reset()
   {
        Response.Write("top.location.href = 'default.asp'");
   }
   
   var strUID = Request.Form("username");
   var strPass = Request.Form("password");
     
   var strRita = perRita;
   var strRitaPass = perRitaPass;
   var strAdmin = perAdmin;
   var strAdminPass = perAdminPass;
       
   var submitFlag = true;
       
   switch (strUID)
   {
                 
             case strRita:
                  if (strPass == strRitaPass)
                  {
                       submitFlag = true;
                  }
                  else
                  {
                       Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                       submitFlag = false;
                  }
             break;    
             case strAdmin:
                  if (strPass == strAdminPass)
                  {
                       submitFlag = true;
                  }
                  else
                  {
                       Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                       submitFlag = false;
                  }
             break;    
             default:
                  Response.Write("Error:  You have entered an incorrect user name and/or password.  Please go back and try again.");
                  submitFlag = false;
                 
   }
   if(submitFlag){
        Response.Write("<BODY onLoad='javascript:document.frmMain.submit()'>");
   }else{
        Response.Write("<BODY>");
   }
</SCRIPT>
     <FORM name="frmMain">
     </FORM>
</BODY>
</HTML>
0
 

Author Comment

by:programming_novice
ID: 6374569
OK, after several constant problems, I've changed my code to the following:

-----------------------------------------------------------

<%@ Language=VBScript %>
<% Option Explicit %>

<HTML>
<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META NAME="Copyright" Content="Copyright (C) 2001 Fierro Creative Productions & Daniel Fierro">
<META NAME="Author" Content="Daniel Fierro - danielfierro@fierrocreative.com, penpilot2001@hotmail.com">

<!--#include virtual="/adovbs.inc"-->
<!--#include virtual="/per.inc"-->

<TITLE>PE Records</TITLE>

<SCRIPT LANGUAGE="JScript" runat=server>

     function Reset()
     {
          Response.Write("top.location.href = 'default.asp';");
     }
     
     var strUID = Request.Form("username");
     var strPass = Request.Form("password");
     
     var perRita = "Rita";
     var perRitaPass = "whs";
     var perAdmin = "Admin";
     var perAdminPass = "cerritos";
     
     var strRita = perRita;
     var strRitaPass = perRitaPass;
     var strAdmin = perAdmin;
     var strAdminPass = perAdminPass;
     var submitFlag = true;
     
          switch (strUID)
     {
          case strRita:
               if (strPass = strRitaPass)
               {
                    submitFlag = true;
               }
               else
               {
                    Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                    submitFlag = false;
               }
               break;
               
          case strAdmin:
               if (strPass = strAdminPass)
               {
                    submitFlag = true;
               }
               else
               {
                    Response.Write("Error:  You have entered an incorrect password.  Please go back acnd try again.");
                    submitFlag = false;
               }
               break;
               
          default:
               Response.Write("Error: You have entered an incorrect user name and/or password.  Please go back and try again.");
               submitFlag = false;
     }
     
     if (submitFlag)
     {
          Response.Write("<BODY onLoad='javascript:document.frmMain.submit()'>");
     }
     else
     {
          Response.Write("<BODY>");    
     }
     
</SCRIPT>

</HEAD>

<FORM name=frmMain action=verify2.asp method=POST id=frmMain>
     <INPUT type="hidden" name="UID" value=<%strUID%>>
     <INPUT type="hidden" name="PWD" value=<%strPass%>>
</FORM>

</BODY>

</HTML>

-----------------------------------------------------------

I'm still getting the same error as before:

It says (or my code says) that I've entered an incorrect user name and/or password, even if I've entered correct values?

Also, because this is really important and I'm running on deadline, I've raised the number of points to 200 (it'll leave me with 6 points, but I'm desperate for an answer, so oh well).
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6375315
Hi,
  I am using IIS server to run the below example and it works fine.
 

<%@ Language=VBScript %>
<% Option Explicit %>

<HTML>
<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META NAME="Copyright" Content="Copyright (C) 2001 Fierro Creative Productions & Daniel Fierro">
<META NAME="Author" Content="Daniel Fierro - danielfierro@fierrocreative.com, penpilot2001@hotmail.com">

<TITLE>PE Records</TITLE>

<SCRIPT LANGUAGE="JScript" runat=server>

    function Reset()
    {
         Response.Write("top.location.href = 'default.asp';");
    }
   
    //var strUID = Request.Form("username");
    //var strPass = Request.Form("password");
    var strUID = "Rita";
    var strPass = "whs";
   
    var perRita = "Rita";
    var perRitaPass = "whs";
    var perAdmin = "Admin";
    var perAdminPass = "cerritos";
   
    var strRita = perRita;
    var strRitaPass = perRitaPass;
    var strAdmin = perAdmin;
    var strAdminPass = perAdminPass;
    var submitFlag = true;
   
         switch (strUID)
    {
         case strRita:
              if (strPass = strRitaPass)
              {
                   submitFlag = true;
              }
              else
              {
                   Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                   submitFlag = false;
              }
              break;
             
         case strAdmin:
              if (strPass = strAdminPass)
              {
                   submitFlag = true;
              }
              else
              {
                   Response.Write("Error:  You have entered an incorrect password.  Please go back acnd try again.");
                   submitFlag = false;
              }
              break;
             
         default:
              Response.Write("Error: You have entered an incorrect user name and/or password.  Please go back and try again.");
              submitFlag = false;
    }
   
    if (submitFlag)
    {
         Response.Write("<BODY onLoad='javascript:document.frmMain.submit()'>");
    }
    else
    {
         Response.Write("<BODY>");    
    }
   
</SCRIPT>

</HEAD>

<FORM name=frmMain action=verify2.asp  method=POST id=frmMain>
    <INPUT type="hidden" name="UID" value=<%=strUID%>>
    <INPUT type="hidden" name="PWD" value=<%=strPass%>>
</FORM>

</BODY>

</HTML>

0
 

Author Comment

by:programming_novice
ID: 6376108
nimaig - I copied your code exactly and the following is all the code of my page:

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

<%@ Language=VBScript %>
<% Option Explicit %>

<HTML>
<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META NAME="Copyright" Content="Copyright (C) 2001 Fierro Creative Productions & Daniel Fierro">
<META NAME="Author" Content="Daniel Fierro - danielfierro@fierrocreative.com, penpilot2001@hotmail.com">

<!--#include virtual="/adovbs.inc"-->

<TITLE>PE Records</TITLE>

<%

     Dim strUID
     strUID = Request.Form("username")
     
     Dim strPass
     strPass = Request.Form("password")
     
%>

<SCRIPT LANGUAGE="JScript" runat=server>

     function Reset()
     {
          Response.Write("top.location.href = 'default.asp';");
     }
     
     var strUID = Request.Form("username");
     var strPass = Request.Form("password");
     
     var perRita = "Rita";
     var perRitaPass = "whs";
     var perAdmin = "Admin";
     var perAdminPass = "cerritos";
     
     var strRita = perRita;
     var strRitaPass = perRitaPass;
     var strAdmin = perAdmin;
     var strAdminPass = perAdminPass;
     var submitFlag = true;
     
     switch (strUID)
     {
          case strRita:
               if (strPass = strRitaPass)
               {
                    submitFlag = true;
               }
               else
               {
                    Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                    submitFlag = false;
               }
               break;
               
          case strAdmin:
               if (strPass = strAdminPass)
               {
                    submitFlag = true;
               }
               else
               {
                    Response.Write("Error:  You have entered an incorrect password.  Please go back acnd try again.");
                    submitFlag = false;
               }
               break;
               
          default:
               Response.Write("Error: You have entered an incorrect user name and/or password.  Please go back and try again.");
               submitFlag = false;
     }
     
     if (submitFlag)
     {
          Response.Write("<BODY onLoad='javascript:document.frmMain.submit()'>");
     }
     else
     {
          Response.Write("<BODY>");    
     }
     
</SCRIPT>

</HEAD>

<FORM name=frmMain action=verify2.asp method=POST id=frmMain>
     <INPUT type="hidden" name="UID" value=<%=strUID%>>
     <INPUT type="hidden" name="PWD" value=<%=strPass%>>
</FORM>

</BODY>
</HTML>

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

I'm still getting my error message about the username being incorrect.  BTW, I'm running this on PWS.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6378677
May I know from where r u getting this value.

var strUID = Request.Form("username");
var strPass = Request.Form("password");

Try with some constant value like

var strUID = "Rita";
var strPass = "whs";
   
   
   
   
0
 

Author Comment

by:programming_novice
ID: 6380779
This is a verification page for a web database app.  strUID is the value of the information sent from the previous log-in page.  There are multiple users (only two in this example), which is why I need to know what the value is each time, and not use a constant.
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6382812
I never meant to tell you to use constant. I told u to check if the code works using constant. Anyway, I have rectified the problem u r facing. Try the code below.


<%@ Language=VBScript %>
<% Option Explicit %>

<HTML>
<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META NAME="Copyright" Content="Copyright (C) 2001 Fierro Creative Productions & Daniel Fierro">
<META NAME="Author" Content="Daniel Fierro - danielfierro@fierrocreative.com, penpilot2001@hotmail.com">
<TITLE>PE Records</TITLE>

<%

    Dim strUID
    strUID = Request.Form("username")
   
    Dim strPass
    strPass = Request.Form("password")
   
%>

<SCRIPT LANGUAGE="JScript" runat=server>

    function Reset()
    {
         Response.Write("top.location.href = 'default.asp';");
    }
   
    var strUID = String(Request.Form("username"));
    var strPass = String(Request.Form("password"));
   
       
   
    var perRita = "Rita";
    var perRitaPass = "whs";
    var perAdmin = "Admin";
    var perAdminPass = "cerritos";
   
    var strRita = perRita;
    var strRitaPass = perRitaPass;
    var strAdmin = perAdmin;
    var strAdminPass = perAdminPass;
    var submitFlag = false;
   
   
    switch (strUID)
    {
         case strRita :
              if (strPass == strRitaPass)
              {
                   submitFlag = true;
              }
              else
              {
                   Response.Write("Error:  You have entered an incorrect password.  Please go back and try again.");
                   submitFlag = false;
              }
              break;
             
         case strAdmin :
              if (strPass == strAdminPass)
              {
                   submitFlag = true;
              }
              else
              {
                   Response.Write("Error:  You have entered an incorrect password.  Please go back acnd try again.");
                   submitFlag = false;
              }
              break;
             
         default :
              Response.Write("Error: You have entered an incorrect user name and/or password.  Please go back and try again.");
              submitFlag = false;
             
    }
   
    if (submitFlag)
    {
         Response.Write("<BODY onLoad='javascript:document.frmMain.submit()'>");
    }
    else
    {
         Response.Write("<BODY>");    
    }
   
   
</SCRIPT>

</HEAD>

<FORM name=frmMain action=verify2.asp method=POST id=frmMain>
    <INPUT type="hidden" name="UID" value="<%=strUID%>">
    <INPUT type="hidden" name="PWD" value="<%=strPass%>">
</FORM>

</BODY>
</HTML>

0
 

Author Comment

by:programming_novice
ID: 6385347
Ok, well, now I don't get my error all the time, and if I enter an incorrect username, I get the correct error (thanks).  However, as long as it's a valid username, I get logged in, even if I enter an incorrect password.  Any suggestions?

Thanks again.
0
 
LVL 9

Accepted Solution

by:
nimaig earned 231 total points
ID: 6387519
I saw your previous code. You are checking for the password something like this

 strPass = strRitaPass

which is not correct. '=' is a assignment operator. The correct way of doing is

 strPass == strRitaPass

i.e. using '=='

Hope this helps !!!!!!!!!!1
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7014180
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20092481.html
http://www.experts-exchange.com/questions/Q.20099845.html
http://www.experts-exchange.com/questions/Q.20099844.html
http://www.experts-exchange.com/questions/Q.20114481.html
http://www.experts-exchange.com/questions/Q.20122589.html
http://www.experts-exchange.com/questions/Q.20165600.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7175073
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now