Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Form Values - Object expected

Status
Not open for further replies.

RWF

Programmer
Apr 16, 2001
24
US
The code is supposed to read through a server text file and set the check boxes on the client display accordingly. It doesn't like the following:

Programx.asp
------------
<HTML>
<HEAD>

<script language=&quot;VBScript&quot; runat=server>
<!--
sub ReadData()

Const ForReading = 1
Dim fso, FileData

Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set FileData = fso_OpenTextFile(&quot;Data.txt&quot;, ForReading, False)

'do file stuff

if condition then
Document.TheForm.rr(0).Value = Checked
end if

end sub
//-->
</script>

</HEAD>
<BODY onLoad=&quot;ReadData()&quot;>
<FORM name=&quot;TheForm&quot;>

<TABLE border=1>
<tr>
<td><input name=rr type=checkbox></td>
<td><input name=rr type=checkbox></td>
</tr>
</TABLE>

</FORM>
</BODY>
</HTML>

Who wants a star?
 
Tell me if this does it for you.

<HTML>
<HEAD>

<script language=&quot;VBScript&quot;>
<!--
sub ReadData()
Document.TheForm.rr(0).checked = True
end sub
//-->
</script>

</HEAD>
<BODY onLoad=&quot;ReadData()&quot;>
<FORM name=&quot;TheForm&quot;>

<TABLE border=1>
<tr>
<td><input name=&quot;rr&quot; type=&quot;checkbox&quot;></td>
<td><input name=&quot;rr&quot; type=&quot;checkbox&quot;></td>
</tr>
</TABLE>

</FORM>
</BODY>
</HTML>
 
where are you getting the error?

&quot;object expected&quot; error sounds like it doesn't have fso still available when it needs it, and if it needs anything from fso outside of the ReadData function, that would make sense, since you Dim fso and create the object within the function, making it unavailable outside of the function....
 
My bad qsac, I sent the wrong info. The .checked=true works as I found out later on. Nice catch though.

lobstah, the error occurs sometime after/during when the function has been executed.

The &quot;file stuff&quot; is not a problem. I left it there to indicate it is necessary to be using the files on the server at that time.

The problem is as you indicate. It seems the server side procedure cannot see the form and/or values declared on the client side.

There is a 1:1 dependency between the form presented to the client, and the files residing on the server.

It seems the &quot;client side&quot; needs to actually be run from the server for this to work, e.g.

<%Response.write(all client html code)%>

Unless there is a way to pass the form &quot;array&quot; to the procedure and somehow have it dynamically update the client screen.
 
change:
sub ReadData()
to:
function ReadData()

dim sFileStuff
'do file stuff, storing in sFileStuff
ReadData = sFileStuff
end function

' a function can return a value, so if you are getting the file line by line, then it will return a line of text in FileStuff, or the whole text file, whichever...
' then to call the function, store the value returned in a variable outside the function, to be used in the rest of your code.

Dim strFileStuff
strFileStuff = ReadData()


----- does that make sense?
 
Makes perfect sense. And after all this I believe the &quot;Object expected&quot; problem was caused by issuing a function call in the <BODY> tag &quot;<BODY onload=x()&quot;.

Apparently not legal in an ASP file, or I did not construct the code properly.

As soon as I removed the &quot;onload&quot; the error went away.

Now I am almost there, and have only one final issue to resolve.

I need to submit a form from one Asp to another, and have the elements in the first screen updated.

Everything executes as desired, but does not refresh the first screen. Note that I must use the POST method, as the querystring could easily exceed 2K in length in the real program.

The following does not update the check boxes in programx.asp from changes in setdata.asp

programx.asp
------------
<HTML>
<HEAD>

<script language=&quot;VBScript&quot; type=&quot;text/vbscript&quot;>
<!--
sub Validate(x)
TheForm.action=&quot;SetData.asp&quot;
TheForm.Submit
end sub
//-->
</script>
</HEAD>

<BODY>
<FORM name=&quot;TheForm&quot;>
<TABLE border=1>
<tr>
<td><input name=rr type=checkbox></td>
<td><input name=rr type=checkbox></td>
<INPUT name=&quot;process&quot; type=&quot;button&quot; value=&quot;Refresh&quot; onclick=&quot;Validate()&quot;>
</tr>
</TABLE>
</FORM>
</BODY>
</HTML>


setdata.asp
------------
<%
rr = Request.Form(&quot;rr(1)&quot;)

rr = Checked 'also tried True, same result.

Response.Redirect(&quot;programx.asp&quot;)
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top