...

View Full Version : Functions & Arrays Urgent help needed



cypher083
07-10-2004, 04:36 PM
I am currently studying JavaScript, and the examples in the textbook is worth SQUAT!! Please help with the following problem.

A company has a news letter and they want it to be displayed on a web page. They asked you to create a web page that will allow for easy updates each month. The page should be displayed in frames. When the user clicks a news item on the left then the item must open in the right frame.

1. Create a function to initialise a new array that will store each newsletter news item and its URL.

2. Create a function that will add a newsletter item to the array. The function should accept a headline and associated URL.

3. Create the array that will store the news item by calling the function created in steps 1 & 2.
IMPORTANT TAX LAW CHANGES - tax.htm
DEDUCTING MEDICAL EXPENSES - medical.htm
RETIREMENT PLANNING - retire.htm
UPCOMING SEMINARS - seminars.htm

4. In the BODY portion of the Web page, enter the code that will display the array items constructed in step 3.


PLEASE HELP!!

regards
cypher

SpiritualStorms
07-10-2004, 05:38 PM
Out of curiousity, do you know what JavaSCript is? Do know what its capable of?

cypher083
07-10-2004, 06:08 PM
Well, I only started with JavaScript earlier this year for the first time, but the examples in the textbooks are not very informative. Why do you ask?

SpiritualStorms
07-10-2004, 06:11 PM
I ask because it seems like what you want would entail something other than JavaScript. From what i know, JavaScript can not technically read from files, or write to files, or at least, files that are not HTML. You want for some sort of updater, correct?

cypher083
07-10-2004, 06:26 PM
To tell you the truth I have no idea what to do with this. The problem in the original post is an exact copy of the one I need to complete for an assignment, but the damn thing does not make sense. I think I might be on my way to an answer for the first part. Take a look and tell me what you think.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Parallel Array Test</title>
<script language="JavaScript">

function newsArray()
{
var Result = "";
items = ["item1"]
url = ["http://www.hotmail.com"]
for (i=0; i<items.length; i++)
{
Result += document.write(items[i].link(url[i])) +"\n" ;
{
return Result;
}
}
}
</script>
</head>

<body>
<form name="left">
<a href="javascript:newsArray()">The first link</a>

</form>
</body>
</html>

dumpfi
07-11-2004, 12:05 AM
This might help you although i don't see any sense in doing this with a client-side programming language
<html>
<head>
<script type="text/javascript">
function news() {
this.content = [[], []];
this.add = function(desc, url) {
this.content[0].push(desc);
this.content[1].push(url);
}
this.display = function(parent_el) {
var div = document.createElement("div");
for(var i = 0; i < this.content[0].length; i++) {
var anchor = document.createElement("a");
anchor.setAttribute("href", this.content[1][i]);
var desc = document.createTextNode(this.content[0][i]);
anchor.appendChild(desc);
div.appendChild(anchor);
div.appendChild(document.createElement("br"));
}
parent_el.appendChild(div);
}
}
function init() {
news = new news();
news.add("IMPORTANT TAX LAW CHANGES", "tax.htm");
news.add("DEDUCTING MEDICAL EXPENSES", "medical.htm");
news.add("RETIREMENT PLANNING", "retire.htm");
news.add("UPCOMING SEMINARS", "seminars.htm");
news.display(document.getElementsByTagName("body")[0]);
}
window.onload = init;
</script>
</head>
<body>
</body>
</html>dumpfi

gohankid77
07-11-2004, 12:40 AM
Think of it this way: It's a textbook! It is useless to consult it! The Internet has better, clearer information!

Basscyst
07-11-2004, 01:06 AM
You could think of it that way. But a text book will go into far more depth of a programming language and they are nice to have around. For one the information therein has gone through an editor and and been published as fact. There is no such process with a webpage. The internet is good for the basics and in a case where you may need a different explanation giving this forum a nice little place in the world.

Basscyst

gohankid77
07-11-2004, 01:09 AM
I reckon your right Mr. Bass.

cypher083
07-11-2004, 10:22 AM
THANX!! Just one more thing. How can I display the contents of the selected URL in another frame instead of a new window?

cypher083
07-11-2004, 10:34 AM
Nevermind I just made a little spelling mistake when I set the attributes, everything is working fine now.

HiEverybody
07-11-2004, 01:23 PM
GoodDay

I am doing the exact same assignment as Mr Cypher083

Thanx to Mr Dumpfi everthing is working except,

Can anybody help me to display the contents of the selected URL in the body frame instead of a new window? I have 2 frames: A Left Frame and a right (body) frame.

The link to the url is in the left frame and when clicked it must open in the right frame.

Please Help???

Willy Duitt
07-11-2004, 04:07 PM
Hint: Change this line to target your iframe....

window.onload = init;

HiEverybody
07-11-2004, 04:18 PM
Thank You Mr Willy Duitt. I appreciate your help and I see you gave a comment on my other question for the calculation.

I am going to look at it now

Thanx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum