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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables in text files

Status
Not open for further replies.

johnsimpson

Programmer
Mar 28, 2006
60
GB
Hi Guys,

Is it possible for me to store a value (i.e. 850) in a .txt file and then call upon and use this value for a variable

i.e.
var myvariablename = valueoftxtfile

thanks
John
 
Yes.

However, it's not very highly suggested. To modify files on a user's local machine requires ActiveX objects which will run in IE only. Additionally, it will pop up a security warning that a potentially malicious function is trying to run. This scares off a lot of people (rightfully so).

What you'd probably want to do anyway is write the value to a cookie. That's what cookies were designed to do for web applications. The downside to this is that cookies can be disabled on a user's machine. However, this is still a favorable option to using an activex routine.

Here's a pretty detailed explanation of how to use cookies with javascript. It also provides functions for you that you can pretty much just drop straight into your page:


-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Have a look at my FAQ from 2004, "How do I write counter code that works from a local or network text file?": faq216-5305

While IE-only, it covers pretty much what you've asked for.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Sorry guys, dont think i explained it properly, i wanted the script to read from a text file on the server. It is to contain a numeric value which will be updated regulary.

Anyway I managed to suss that anyway using

<script type="text/javascript" src="house_team_scores.txt"></script>

and declaring the variables in the .txt file.

Seems to work anyway, but what im interested in now is I want to be able to use these variables to set the height of an image.

If you look at
I want to change the spacer image of the rockets. So they will be 90% of the value in the text file. Is that possible?



Thanks for your help so far guys, appreciated!
 
What server-side scripting language do you have available to you? That's your best bet for this kind of thing. If you use client-side Javascript and someone has JS turned off in their browser, your programming won't work. Since the text file is on the server and has to be read from the server, then just use server-side scripting to read and use the contents of the file.

Lee
 
Sure, that's a real common server-side scripting language. You should be able to find something real easily on Google for PHP tutorials.

Lee
 
You'll probably get a lot better responses for your question in the PHP forum (forum434) now that the total scope of the problem has been identified.

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
thanks for your help guys,

fixed the alignment, couldn't be bothered last night, i will search for some PHP solutions,

thanks
J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top