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

Update HTM L page w/Javascript and Flat File?

Status
Not open for further replies.

finny

Programmer
Nov 16, 2000
58
US
Hi All,
I know this can be done w/ASP but I was wondering if there is another way to complete the following task using only HTML pages and JS.

I need to update a HTML page on a daily basis w/current inventory data. I would create a download from DB and place it in a flat file on web-server. From there can I use JS to access flat file and recreate webpage based on the data in the flat file?

I am just fishing here for info, whether it can be done or do I have to go in another direction. Any input would be greatly appreciated. If more info is needed, I will readily supply.

thx...Joe
 
It's possible if you do just a little with your flat file output before posting on the web. I would reommend some sort of macro to do the following:

Generate your flat file, then remove all line breaks, so it is one long string, (probably a good idea to replace line breaks with some sort of character, so you can use regex to distinguish one record from the next) then have a macro place the following before the string:

Code:
my_data = "{your db output with line breaks removed}"

Then in your HTML page:

Code:
<script language=&quot;Javascript&quot; src=&quot;your_flat_file&quot;>
<script>
<script language=&quot;Javascript&quot;>
function manipulate_file()
{
[whatever you want to do with variable 'my_data', using regex or other string operations to split records and columns into an array, then output in a table]
}
</script>
Even better yet, just use your macro to turn the data into a string complete with HTML markup and just use your manipulate_file() function to
Code:
document.write(my_data)
the data wherever you want.
 
rycamor,
thx for the quick reply. I was browsing throught the forum and most of the posts I came across was led me to believe I needed to used a CGI to accomplished my task. I will give your suggestion a try. Another question I have, what do you mean by &quot;regex&quot;. Forgive my ignorance(or lack of experience) but I haven't heard that before.

thx...joe
 
rycamor,
follow up...
Regex = Regular Expression

Right/Wrong?

So I will have to learn Perl to accomlish my task...that's ok too.

Learning as I go

thx...joe
 
joe/finny, you can use reg exps in jscript as well - no need to learn perl :)
 
iza,
thx for the info. It's good to know.
And just so I know that I'm on the same page as you, Reg Exp refer to
ex: string.substring, string.IndexOf and so on...

thx...joe
 
There are quite a few string operations you can do without using regular expressions, and you should probably try to solve your problem with those first, but Javascript does support many of the same regular expression abilities that Perl does. Read the Javascript documentation at and at
 
&quot;string.substring, string.IndexOf and so on... &quot; are string functions
reg exps look like [A-Z]^z ... they are patterns to which we compare strings (for instance, to validate an email adress, you have to check if it's the &quot;form&quot; xxx@xxx.yyy where xxx can hold any char but @, yyy can't be longer than 3 chars, can't hold other chars than a-z ... it's 1 line of code using a reg exp)

 
You can also do this sort of thing in pure HTML using data binding. I haven't used it in anger, just came across it in a tutorial, but you could give it a try. I'll post an example below (sorry for the long post!)

File: data_binding.html
Code:
<html>
<head>

<object id=&quot;stocks&quot; classid=&quot;clsid:333C7BC4-460F-11D0-BC04-0080C7055A83&quot;>
<param name=&quot;DataURL&quot; value=&quot;stocks.txt&quot;>
<param name=&quot;UseHeader&quot; value=&quot;TRUE&quot;>
</object>

<title>HTML Skeleton</title>
</head>
<body style=&quot;font-family: Verdana&quot;>

<table border=&quot;1&quot; id=&quot;stocktable&quot; datasrc=&quot;#stocks&quot;>
<tr>
<td><div datafld=&quot;Symbol&quot;>Stock Symbol</div></td>
<td><div datafld=&quot;Company&quot;>Company Symbol</div></td>
<td><div datafld=&quot;Quote&quot;>Quote Symbol</div></td>
<td><div datafld=&quot;Change&quot;>Change Symbol</div></td>
<td><div datafld=&quot;Volume&quot;>Volume Symbol</div></td>
</tr>
</table>
<br><br><br>
<div id=&quot;sortlist&quot; align=&quot;center&quot;>
<font size=&quot;-2&quot;>
<a href=&quot;#&quot; onClick=&quot;stocks.sortColumn='Symbol';stocks.reset();&quot;>Sort by Symbol</a> | 
<a href=&quot;#&quot; onClick=&quot;stocks.sortColumn='Company';stocks.reset();&quot;>Sort by Company</a> | 
<a href=&quot;#&quot; onClick=&quot;stocks.sortColumn='Quote';stocks.reset();&quot;>Sort by Quote</a> | 
<a href=&quot;#&quot; onClick=&quot;stocks.sortColumn='Change';stocks.reset();&quot;>Sort by Change</a> | 
<a href=&quot;#&quot; onClick=&quot;stocks.sortColumn='Volume';stocks.reset();&quot;>Sort by Volume</a>
<br>
</font>
</div>
</body>
</html>
This is the datafile - stocks.txt. The 1st line gives you the column headings, and a data type if required. The rest is the data, with comma separated fields.
Code:
Symbol,Company,Quote:FLOAT,Change:FLOAT,Volume:INT
HWP,Hewlett-Packard,10,10,400556
IBM,IBM,10,20,40022
AAPL,Apple Computer,10,30,40021
NSCP,Netscape,10,50,20002
MSFT,Microsoft,10,40,4002
AOL,America Online,30,85,31

These 2 components should be all you need to test the idea. Hope this makes some sense.

Greg.
 
Grega, iza and rycamor,
thx for all the info. Grega, I'll be trying your suggestion out later on today. thx again....joe
 
I tried using the data binding example above and it works fine with IE but no go with netscape. This is my first try with data binding and I don't know anything about it. Does this not work for netscape? If not then it is no good in my opinion. Any solutions?
 
The reserach i have done indicates that data binding is not supported in netscape. seems i need to use java applets to access this. is this right?? if i do need to use the java applets i may want to go another direction alltogether. i have multiple text files which i need to pull data from and present in a table format on multiple pages. doesn't need to be fancy but needs to be fail safe and work on both netscape and ie. i'd really like the simplest solution so if you any ideas please help.
 
is anyone reading this??
usually doesn't take this long to get a response
 
how about XML? depending on the database you pull your feed from, it may even be able to export the data directly to XML. then use javascript to read in the XML file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top