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

Newbie Question: JavaScript and Files.. Possibilities?

Status
Not open for further replies.

DJVisuaL

Programmer
May 31, 2000
52
US
I am gonna start a links page and basically what I wanna do is make the links have ratings... so I want to put links/ranks/description/etc.. in a text file 1 per line and put it on the webserver and then have some kind of script that makes an html page from the data. Is this possible with JavaScript? I hope so because I don't want to have to hard code a page everytime I get a new link because they will change positions based on the rank they have! The server I'm on doesn't have CGI or ServerSide Java or anything like that so JavaScript is my only hope (I think?) any help is appreciated!
thanks
DJ
 
Sorry, the very nature of javascript keeps this from happening on the client-side. Get yourself another provider. One that provides CGI/ASP/whatever. You can usually get 10MB or more of web space for next to nothing a month. If you have DSL or cable you can set up your own web-server (much more fun). Consider the following options...

1. Internet Information Server with Active Server Pages. Using ADO (Active Data Objects) you can use either VBScript or JavaScript to read and write to any database or text file (on the server or another machine within your administrative control) so long as you have a proper ODBC connection or use DSN-less connections. This database (whether SQL or a text file) can hold HTML script.

2. Netscape provides a Web Server with server-side javascript that can read text files (and use ODBC)

3. There are many other web server scripting agents that can do this on a Linux/Unix or Mac platform.

Hope this helps,
Rob
[sig][/sig]
 
RobSchultz is right. Your provider should provide _some_ sort of dynamic processing. Are you sure they dont let you use server-side includes? That would be a simple way to solve your problem, and every webserver out there can process basic includes, if so desired.

However, just as an intellectual exercise, it is possible to use Javascript with an external text file to accomplish what you want. You will just have to do a bit of extra work when editing the text file.

The easiest way is simply to put document.write( before each line of your text, and then enclose it at the end of the line with ) .

But you will have to include some HTML inside each line of text, as well as escaping quotes and other special characters with a backslash \ .

Use
..html stuff...
<SCRIPT Language=&quot;Javascript&quot; src=&quot;yourtextpage.js&quot;>
</SCRIPT>
..back to html stuff...

If you want to really get spiffy, though, you could just
a) remove all carriage lines from your text file before saving
b) make that whole string be the value of a variable at the beginning of the file
c) use another Javascript function already inside your page to parse that string variable using regular expressions to put the appropriate HTML and links around your text.
d) document.write that variable into its place on your page.

This will probably be a lot more work than just changing your host provider, though.

[sig][/sig]
 
Good idea rycamor. I forgot about using <script src=..>. That would get around the server-side scripting issue.

Kudos,
Rob [sig][/sig]
 
OK Thanks!! Do you guys know any free servers that allow any form of CGI/serverside?
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top