Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Global var in HTML page.

Posted on 1999-07-26
5
Medium Priority
?
205 Views
Last Modified: 2013-12-24
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?
0
Comment
Question by:ylix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:mSH
ID: 1868266
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.

0
 

Author Comment

by:ylix
ID: 1868267
I don't want to use database,then I'd like to use the others
 ways,can you provide me some example.Thank you.
0
 
LVL 1

Accepted Solution

by:
mSH earned 400 total points
ID: 1868268
YourName.ASP

<%response.buffer=true%>
<html>
<% Response.Cookies("UserName").Expires = DateAdd("m", 4, Now()) %>
<head>
<title>New Page 1</title>
</head>
<body>
<form name="form1">
<input type="hidden" name="ClientName" value='<%=request.cookies("UserName")%>'>
</form>
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;
      document.write(a);
   }
</script>
<%=request.cookies("UserName")%>, how're you?
</body>
</html>


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.

0
 

Author Comment

by:ylix
ID: 1868269
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?
0
 
LVL 1

Expert Comment

by:mSH
ID: 1868270
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

GLOBAL.ASA
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
   Application("Number") = 0
End Sub
</SCRIPT>

INCREMENT.ASP
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
If request.form("OK")<> "" then
   Application.Lock
   Application("Number") = Application("Number") + 1
   Application.Unlock
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">
</form>
</BODY>
</HTML>

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.

0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question