Global var in HTML page.

In a page,I want to record the data user inputed in a textbox,and show it when the user opens the page.I think I need a global variable.But I don't know where to define it and how to use it.Will somebody tell me?
Who is Participating?
mSHConnect With a Mentor Commented:

<% Response.Cookies("UserName").Expires = DateAdd("m", 4, Now()) %>
<title>New Page 1</title>
<form name="form1">
<input type="hidden" name="ClientName" value='<%=request.cookies("UserName")%>'>
Hi <script language=javaScript>
   if (document.form1.ClientName.value == '') {
      a = prompt("Give me your name, please", "");
      document.form1.ClientName.value = a;
      document.cookie = "UserName=" +a;
<%=request.cookies("UserName")%>, how're you?

Brow this page in the first time and then refresh, close browser and brow it again...

This one just a simple example. It was a mix betwwen  VBScript and JavaScript. Don't care much about it. You have to read carefully about cookie in both VBS and JS and write code your self. No one use code for cookie like this.

There 3 way to do that.
- Use a database or a file and record data in it. U have to experience with ADO.
- Use a GLOBAL.ASA file. Data just save in Server in operating time. That is, when you stop WWW service or restart server, those ifo will lost.
- Use a cookies. I think that best fit your request because of simple and fast. You can do it by Java script in HTML page (document.cookie) or VBScript in ASP file(request.cookie, response.cookie).

So please choose which one do you prefer and then we'll help you more.

ylixAuthor Commented:
I don't want to use database,then I'd like to use the others
 ways,can you provide me some example.Thank you.
ylixAuthor Commented:
I'll try this method.
I have attempted to use the global.asa method,and I initialized a var in the application_onstart event,I place a button in a page,when the button is clicked,I increse 1 to the var.But it doesn't work as my thought.
How to use the global.asa file?
GLOBAL.ASA is server side script. And Button_onClick is client side script. So, it cann't exchange each other.
So If you really want to do that, you have to send info to server, that is, when button click, you have to refresh, submit form or sth like that to server. E.g

Sub Application_OnStart
   Application("Number") = 0
End Sub

If request.form("OK")<> "" then
   Application("Number") = Application("Number") + 1
End if
Number of clicked: <%=Application("Number")%><br>
<form name=Form1 method=post action="increment.asp">
<input type="hidden" name="OK" value="1">
<input type=submit value="Click here">

I didn't use query string because user can refresh and make change var varlue.

One more attention: GLOBAL.ASA must in folder have execute script right.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.