Link to home
Start Free TrialLog in
Avatar of programming_novice
programming_novice

asked on

'document' is undefined?

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.

Avatar of nzjonboy
nzjonboy

programming_novice

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

nzjonboy
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>

Avatar of programming_novice

ASKER

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.
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.
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.
Why you want VBScript to access this method. Can you please explain the scenerio.
>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
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();
           <% } %>
    }
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.
Can you post your code please ...
<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()">
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()">
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.
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>
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).
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>

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.
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";
   
   
   
   
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.
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>

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.
ASKER CERTIFIED SOLUTION
Avatar of nimaig
nimaig
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  https://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.
https://www.experts-exchange.com/questions/Q.20092481.html
https://www.experts-exchange.com/questions/Q.20099845.html
https://www.experts-exchange.com/questions/Q.20099844.html
https://www.experts-exchange.com/questions/Q.20114481.html
https://www.experts-exchange.com/questions/Q.20122589.html
https://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
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://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
Force accepted

** Mindphaser - Community Support Moderator **