Forum Moderators: open
Sub called by onload method has the following:
Sub sub1
dim temp
temp = 0
response.write ("XXX")
{more code to test global variables intialized by the VBscript run to acquire the info from the Access DB }
End Sub
I was just attempting to output a static string before I
tried outputing variable values. The above produces the error. How to I get output during the function call to see what is going on if the above doesn't work.? I have not discovered any other write except the <%= which is a shortcut to the other form and produces same error.
This is my first attempt at using ASP and ADO etc.
BODY onload is used to run client-side scripts, if you want to display data from a database you (usually) do this server-side, before sending the page to the browser.
Check out some simple asp examples on the developers sites to do database reads etc, sticky me if you want some links.
<added...and welcome to webmaster world:)</added>
Intended application is to read Access DB to initialize the state of <BUTTON> tags .. at this time just setting background color. (Eventually to click on BUTTON and reset value back in the AccessDB>) My ADO script appears to be working okay and retrieves correct data, it is defined before the <BODY> in my ASP file within <%...%>. The other functions where defined outside the body as well but within <Script language="vbscript">...</script> tags and I guess this makes them client side , which I didn't know. The sub executed "onload" set the background colors to static values ("red", "green" etc.) with no data passed from the results of the ADO objects. This is where I lose control.
In the server side code I set the retrieved values into variables declared in the script? Do these persist? If not how do I use the info once I need to process the client side properties? Can I reference in the server side script objects created later in the <BODY>. For example, my client side onload sub declares Button1.sytle.backgroundcolor="Green" where button1 is id of <BUTTON> and this works. I want this property to be dynamic based on what I retrieve in the server side results of the SQL query on my data base.
I have purchased two ASP books but there is still lots to learn. Thanks. BTW.. what is the syntax for passing arguments to a sub in the onload statement.. I am using onload=sub() since I have no args. Since passing args wehn calling subs in VBScript are not delimited within () as they are with functions...
My objective is to set the initial color of the buttons displayed to be red if the DB value is 0 and green if 1.
The way to do this is all on the server side.
First assign variables for the colors based on the data in the recordset
if objRS(0)=1 then
strColor="green"
else
strColor="red"
end if
Then just write the buttons using ASP
Response.write "<input type='button'
style='color:black; height:30; width:100; background:" & strColor & ";'>"
If you want to have onClick events that do different things depending on what was in the database, you have to use the same approach and write ther client-scrript, on the server side! using ASP.
Remember, once the page is displayed in the broswer - the database is closed unless you use some other technology e.g RDO/Client-side data binding.
I Hope this helps, it is confusing, but it is the way to achieve what you want to do in this situation.
My onClick events which I assume are client side still work to change the displayed button styles. Now to get the data back to the database as part of the onclick events...
Thanks...