PDA

View Full Version : Object Required Error? - window / document


Running Bear
06-16-2003, 12:09 PM
Hello,

I'm trying to submit a form without using a button, I'm getting an object required error when referencing window and document? Does anyone know why? I thought they were built in objects?

these are the three errors I've been getting -
Object required: 'window'
Object required: 'document'
Object required: ''



<%@ Language=VBScript %>
<%
Dim UID
Dim PWD

If Len(Request.Form("txtUID")) Then
ProcessPWD()
End If

Function ProcessPwd()
Dim rtnCode
Dim theFrm

Set theFrm = window.document.form1
'Set theFrm = document.form1


UID = Request.Form("txtUID")
PWD = Request.Form("txtPwd")

If (UID = "calvin") And (PWD = "hobbes") Then
rtnCode = 1
Else
rtnCode = 0
End If

Select Case rtnCode
Case 1 ' Login OK
theFrm.Submit

Case Else ' Login Fail
Response.Write("<p>Login Attempt failed please try again" & vbcrlf)
Response.Write("</p>" & vbcrlf)
End Select

End Function
%>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<body>
<p>&nbsp;</p>
<!-- The Auto Submit form -->
<form name="form1" id="form1" action="../autoSubmit/changed.htm" method="post">
<input type="hidden" name="txtUID" id="txtUID" value="<%=UID%>">
<input type="hidden" name="txtPwd" id="txtPwd" value="<%=Pwd%>">
</form>
</body>
</html>


Any help will be appreciated!!

Cheers Al

raf
06-16-2003, 12:58 PM
Not sure what all that is. What are you trying to do? Is this serversided script.? As far as i know, window is not an asp-object.
Anyway your code could be shortened by replacing

Dim UID
Dim PWD

If Len(Request.Form("txtUID")) Then
ProcessPWD()
End If

Function ProcessPwd()
Dim rtnCode
Dim theFrm

Set theFrm = window.document.form1
'Set theFrm = document.form1


UID = Request.Form("txtUID")
PWD = Request.Form("txtPwd")
If (UID = "calvin") And (PWD = "hobbes") Then
rtnCode = 1
Else
rtnCode = 0
End If

Select Case rtnCode
Case 1 ' Login OK
theFrm.Submit

Case Else ' Login Fail
Response.Write("<p>Login Attempt failed please try again" & vbcrlf)
Response.Write("</p>" & vbcrlf)
End Select

End Function

with

If (Request.Form("txtUID") = "calvin") And (Request.Form("txtPwd") = "hobbes") Then
theFrm.Submit ' whatever this is supposed to do
else
Response.Write("<p>Login Attempt failed please try again</p>" & vbcrlf)
end if


But i don't see the use in sending a form to the client you then automatically submit. Not when you use a server sided scripting language... If you wan't to pass the values, just store them in a sessionvariable or cookie or append them to the querystring.
I also noticed that you post the form to an html-page ...

Running Bear
06-16-2003, 01:23 PM
I'm sorry that it appears confusing, I've created this example from my main code, in an attempt to simplify it, clearly unsuccessfully...

In my project I use a dll, and seperate password processing component. When I log in the dll returns all manner of info. from another server i.e. the users profile etc.
When a user is required to change their password the dll only tells me whether the password changed ok or not ok.
What I want to do is when it returns password changed okay I want to re-call the logon process, submitting the new password, which will in turn return the profile and other details that I require.

I don't want the user to have to manually login again.

raf
06-16-2003, 02:15 PM
Hmm. Can't quite link that explanation to your code, but i suppose you know what your doing :D. Anyway, i think you need something like:


<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<%
If (Request.Form("txtUID") = "calvin") And (Request.Form("txtPwd") = "hobbes") Then
Response.Write("<body onload=""document.form1.submit()"">")
Response.Write("<!-- The Auto Submit form -->")
Response.Write("<form name=""form1"" id=""form1"" action=""../autoSubmit/changed.htm"" method=""post"">")
Response.Write("<input type=""hidden"" name=""txtUID"" id=""txtUID"" value=""" & Request.Form("txtUID")""">")
Response.Write("<input type=""hidden"" name=""txtPwd"" id=""txtPwd"" value=""" & Request.Form("txtPwd")& """>")
Response.Write("</form>")

else
Response.Write("<body>")
Response.Write("<p>Login Attempt failed please try again</p>" & vbcrlf)
end if
Response.Write("</body>")
Response.Write("</html>")


--> just build the form, then use the onload event to submit it when the page is loaded in the browser.
Never tried it (since i would pass the values serversided), but it should work. Maybe someone with more javascript-wits knows a better way

<edit> If you run a search on the javascript forum, there are some threads about the best way to have an onload submit </edit>

Running Bear
06-16-2003, 02:37 PM
Raf,

Thanks for that I've got it working now. Result!!!

Cheers Al