Help - Search - Members - Calendar
Full Version: HTML/XHTML importing & exporting
HTMLHelp Forums > Programming > Client-side Scripting
s20001321
I am a newbie in HTML/XHTML…I have met some problems when performing the specific tasks…



<table border="2" cellspacing="3" cellpadding="4">
<tr>
<th colspan="10">aaa</th>
</tr>
<tr>
<td><a href="xxx.htm"><img src="yyy.jpg" alt="zzz" /></a></td>


For this part, it needs to use JavaScript to read the data from .txt file and is separated by “,”…and then display the content in the .htm...How to do it???

These are the few lines in .txt:
itemname,Price,size,in stock,colour

[Bedroom]
single bed,$160,single,yes,wood
double bed,$300,double,yes,wood


Million thanksss…
pandy
You have to use those parameters in the script itself. JS can't access the server's file system.

I have a feeling you would be better off with a solution on the server.

Christian J
Javascript in the form of AJAX can read text files on the server. But a simpler and more reliable approach is to let a server-side script (e.g. PHP) read the text file and produce the HTML.
s20001321
But can I use JS to read the data from .txt and display on .htm without using AJAX?

Since I am not good at programming...
Would you please to show the coding for me if there are any solutions can perform this task...?T_T
Brian Chandler
QUOTE(s20001321 @ May 6 2009, 11:04 AM) *

But can I use JS to read the data from .txt and display on .htm without using AJAX?


"AJAX" is a marketing term, meaning "using those bits of javascript that allow you to read other documents by http request". So no, you can't do this without using "AJAX".

QUOTE

Since I am not good at programming...
Would you please to show the coding for me if there are any solutions can perform this task...?T_T


What does "not good at programming" mean? If you cannot write programs in general, you cannot write programs to do anything specific.

But actually what you should be doing is generating the pages with a script (PHP, Perl, Python, etc) on the server. You need someone with programming understanding to do this.
s20001321
um...
Actually, I need to use Javascript to create the page that can read the content from the .txt file...and display on the .htm page...

The .txt file is in the specific folder in my computer.(even I don't know this is client side or server side...)

p.s. there isn't any AJAX related knowledge in the materials at my side...I don't think that AJAX will be included in this part..@@
Frederiek
Maybe the Wiki will clear things a bit up about what AJAX is: http://en.wikipedia.org/wiki/Ajax_(programming)
Be sure to also read about XMLHttpRequest (link in the wiki article).

BTW, Javascript is a client-side programming language, but with the XMLHttpRequest you can dynamically load content into a web page.
See http://www.quirksmode.org/js/contents.html (Data retrieval at the bottom of the page).
Brian Chandler
QUOTE
um...Actually, I need to use Javascript to create the page that can read the content from the .txt file...and display on the .htm page...


Right, well, look. If you can explain *why* you "need" to use Javascript for this, maybe things will become clearer. Is this homework of some sort?
Christian J
QUOTE(s20001321 @ May 6 2009, 08:21 AM) *

The .txt file is in the specific folder in my computer.

Then only you would be able to access it regardless. If this is some kind of assignment, maybe you are expected to put the contents of the txt file as a string into a javascript? But you probably need to learn HTML before learning javascript.

QUOTE
(even I don't know this is client side or server side...)

Your own computer is client-side (unless you run a web server on it). See http://en.wikipedia.org/wiki/Client-side_scripting
Brian Chandler
QUOTE(Christian J @ May 6 2009, 08:41 PM) *

QUOTE
(even I don't know this is client side or server side...)

Your own computer is client-side (unless you run a web server on it). See http://en.wikipedia.org/wiki/Client-side_scripting


That's not a particularly helpful way to look at it, though. Your own computer is "client-side" in the context of looking at _other_ people's websites, but in the context of your own web pages, even if you do not host your own server, it's "server-side". For example, one sensible way of converting a CSV text file into a web page is with some sort of text processor (PHP, for example) which you run on your own computer, before uploading the result to your server host.
Christian J
QUOTE(Brian Chandler @ May 6 2009, 06:35 PM) *

(PHP, for example) which you run on your own computer

But even if run PHP on your own computer it's still run through a server program (again on your own computer in this case).
Brian Chandler
QUOTE(Christian J @ May 7 2009, 02:21 AM) *

QUOTE(Brian Chandler @ May 6 2009, 06:35 PM) *

(PHP, for example) which you run on your own computer

But even if run PHP on your own computer it's still run through a server program (again on your own computer in this case).


Not as far as I know. You can run php programs from the command line, and they need not be anything to do with a web server. Well, come to that you could generate the web page in question using awk, Fortran, Cobol, Prolog, or whatever. It's just called "running a program". It used to be what you did with computers -- getting something done faster by writing a generic program for doing it.

Christian J
QUOTE(Brian Chandler @ May 6 2009, 07:34 PM) *

Not as far as I know. You can run php programs from the command line, and they need not be anything to do with a web server. Well, come to that you could generate the web page in question using awk, Fortran, Cobol, Prolog, or whatever. It's just called "running a program". It used to be what you did with computers -- getting something done faster by writing a generic program for doing it.

Then using a text editor could be considered "server-side" too. The term "server-side" seems misleading if no server is involved.

But I should rephrase my previous "your own computer is client-side" to "your own browser is client-side". Then it doesn't matter where the browser gets the content from.



s20001321
QUOTE(Brian Chandler @ May 6 2009, 05:42 AM) *

QUOTE
um...Actually, I need to use Javascript to create the page that can read the content from the .txt file...and display on the .htm page...


Right, well, look. If you can explain *why* you "need" to use Javascript for this, maybe things will become clearer. Is this homework of some sort?

It is because the mark contribution guide of the homework is shown as:HTML + CSS + JS, so I think using JS is a must...

Also, the requirement of this section is shown as below and I can only understand I need to show the specific images with related details from the .txt file. Am I right@@...?

Actually, I am willing to learn more about the HTML, even JS. However, I don't have too much time to understand the coding in the short time...(Since the deadline is the coming Sat.)So that's why I am so hurry for this...

I know that my request is unreasonable...but would you mind to provide some coding for this part...?

This is a single “prototype” catalogue page that contains a table (or tables) of all the product items
from one of the categories on offer. (In the second assignment, the content will be generated using
database information and server-side programming allowing all of the categories to be included!)
• For each product item show the thumbnail image and basic details: item name and cost.
o The file details.txt has all the details available. The details are separated by commas.
Hint: It may be worth “importing” and then “exporting” the text file with Excel, but make sure you
clean up the resulting HTML!
• There are many products available, but you only need to show the products for your chosen
category.
• If the visitor clicks on an image we would want to show them more details,
o This is just a prototype site and we don’t have all the images and details yet.
o Make all of the items (the text and/or images) as link to the “details_1.shtml” prototype
page. i.e. no matter which category the user selects the same product will show.
(Assignment 2 will extend this so that the selected product will show)
• You can use a table to present the catalogue data (+CSS), but you must use <th> (heading)
elements for heading cells, and provide a suitable caption and summary for the table
pandy
QUOTE
It is because the mark contribution guide of the homework is shown as:HTML + CSS + JS, so I think using JS is a must...


Couldn't that mean you MAY use JavaScript? For example it could be used to show more details. By popping a smaller window without chrome, to show an initially hidden DIV...



QUOTE
Hint: It may be worth “importing” and then “exporting” the text file with Excel, but make sure you
clean up the resulting HTML!


Where does it say the txt file should be read by the page? Doesn't the above rather indicated the data in the text file should be used when you create the page?
Brian Chandler
QUOTE(s20001321 @ May 7 2009, 10:36 AM) *

QUOTE(Brian Chandler @ May 6 2009, 05:42 AM) *

QUOTE
um...Actually, I need to use Javascript to create the page that can read the content from the .txt file...and display on the .htm page...


Right, well, look. If you can explain *why* you "need" to use Javascript for this, maybe things will become clearer. Is this homework of some sort?

It is because the mark contribution guide of the homework is shown as:HTML + CSS + JS, so I think using JS is a must...



Who knows? For all I know, the people providing this course may be (almost) as clueless as you are. But the question below makes some sense -- and you notice they say that in the next step you will be expected to use a server-side script to generate the page from a database, which is what we told you is the way to do it. I don't see any sensible way you can use javascript to answer the question.

QUOTE


Also, the requirement of this section is shown as below and I can only understand I need to show the specific images with related details from the .txt file. Am I right@@...?



I think they just mean to generate an html page *by hand* from a bit you choose from this text file. Do you know anything about writing html?

QUOTE

Actually, I am willing to learn more about the HTML, even JS. However, I don't have too much time to understand the coding in the short time...(Since the deadline is the coming Sat.)So that's why I am so hurry for this...

I know that my request is unreasonable...but would you mind to provide some coding for this part...?


So you want someone to do your homework for you? Are you expecting to pay? There are unscrupulous people who will do this, but I'm not one of them.

QUOTE

This is a single “prototype” catalogue page that contains a table (or tables) of all the product items
from one of the categories on offer. (In the second assignment, the content will be generated using
database information and server-side programming allowing all of the categories to be included!)
• For each product item show the thumbnail image and basic details: item name and cost.
o The file details.txt has all the details available. The details are separated by commas.
Hint: It may be worth “importing” and then “exporting” the text file with Excel, but make sure you
clean up the resulting HTML!
• There are many products available, but you only need to show the products for your chosen
category.
• If the visitor clicks on an image we would want to show them more details,
o This is just a prototype site and we don’t have all the images and details yet.
o Make all of the items (the text and/or images) as link to the “details_1.shtml” prototype
page. i.e. no matter which category the user selects the same product will show.
(Assignment 2 will extend this so that the selected product will show)
• You can use a table to present the catalogue data (+CSS), but you must use <th> (heading)
elements for heading cells, and provide a suitable caption and summary for the table


Right. So make a "prototype" page... (without using javascript)
Christian J
QUOTE(Brian Chandler @ May 7 2009, 07:02 AM) *

I think they just mean to generate an html page *by hand* from a bit you choose from this text file.

That's my understanding as well (in other words no scripting is expected). They even encourage the use of Excel to do this if you clean up the HTML afterwards, but the cleaning may end up creating more work than writing it all by hand in the first place.

To write HTML tables, see the HTML reference on this site http://www.htmlhelp.com/reference/html40/tables/table.html
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.