Jump to content

Variable scope and initialization


dlogvine

Recommended Posts

I'm trying to make my page display additional text information when "Read more" link or button or checkbox are clicked. I created a test variable determine the flow of the switch, but it looks like it is being initialized every time the asp file is being loaded. I tried to declare this variable in Global.asa file or any other asp file onsite, but the same reinitalization happens again and again. Is there place I can see similar code or is there any good book that teaches about the flow of the asp code inside html? Also how do I code in onClick function to change the variable inside Response.Write function? I did it this way, but the code did not produce any results: If printAll = True ThenResponse.Write("...")End If... <%Response.Write("      <a href="""&"index.asp"" ""onClick="printAll=True""><img src = ""images/icon-more.gif"" width=""13"" height=""13"">")Response.Write("Read More</a></li>")%>Also how could I reload the page index.asp so that modifications to the variable would remain?I got a little confused about the " signs in the next to last Response.Write statement, but the script reader did not complain and the page got loaded.Thank you for help!I'd really appreciate if you could advise about any good ASP/VBScript/HTML tutorial (that talks about their interaction and not about each of them separately)

Link to comment
Share on other sites

HTML and ASP don't interact, HTML is a completely static language. All it does is layout and presentation, no logic. Every time an ASP page gets loaded, it is essentially a new execution. When the page stops, all information is lost, it doesn't automatically transfer from page to page. Each time the page gets loaded it is independent. There might be things in the code that rely on other information, but the code getting executed is independent to anything else, it doesn't depend on future or subsequent executions, it just runs the code in the file. If you want to transfer information from one page to another, there are basically three options. You can use forms or the querystring and pass information through GET or POST, or you can use cookies which the browser will automatically send to the server and will contain whatever you saved in them, or you can use the session which the server will keep track of. You can save whatever variables you want in the session, and they will be available for all pages during that session. A session ends after a certain amount of time of the user not doing anything, I believe the default is 24 minutes. For a "read more" link, you would probably want to pass everything through the URL, like this:read_more.asp?article=123&page=2Here are the correct quotes for the response.write:

Response.Write("      <a href=""index.asp"" onClick=""printAll=True""><img src=""images/icon-more.gif"" width=""13"" height=""13"">")

But keep in mind that the onclick events are handled by Javascript, not ASP. You are setting a Javascript variable called printAll equal to true in that onclick, it doesn't affect ASP at all. Javascript is a client-side language, it doesn't send any information back to the server. ASP runs on the server.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...