PDA

View Full Version : interactive values


ssskaya
10-28-2002, 09:40 PM
I have a page in my site that has a list of stock market indices:

http://www.fiscalstudy.com/major.html

I will use these values on other pages too.

So, I don't want to change exact the same value for a couple of times.

Is it possible to make just one change for one value and get it updated at all other places on the site?

I do not want to update exact the same thing all over again for other pages.

beetle
10-28-2002, 10:41 PM
Well, with javascript you can, but it's not very elegant....a server side solution would be better. Nonetheless, here's the JS way...// external js file - 'stocks.js'
var djia = '7286.27';
var nasdaq = '1114.11';
var sp500 = '776.26';Now, with every page that you link to with that JS file, you can write their values to the page...Dow Jones: <script>document.write(djia);</script><br>
NASDAQ: <script>document.write(nasdaq);</script><br>
S&P 500: <script>document.write(sp500);</script><br>Etc etc....

ssskaya
10-29-2002, 10:37 AM
what function should I use for variables? do I just list them?

beetle
10-29-2002, 01:15 PM
Right, just list (define) them. They will all be global variables...

ssskaya
10-29-2002, 10:47 PM
here's how it is:
------------------on the page:

<td align="center"><strong>DJIA</strong></td>
<td align="right"><script language="JavaScript"
src="http://www.fiscalstudy.com/values.js"><!--
document.write(djia)
// --></script><br>

----------------on the external file:

var djia = "7286.27";
var nasdaq = "1114.11";
var sp = "776.26";
var nikkei = "776.26";
var ftse = "776.26";
var dax = "776.26";
var cac = "776.26";
var hang = "776.26";
var amsterdam = "776.26";
var australia = "776.26";
var milan = "776.26";
var new = "776.26";
var singapore = "776.26";
var south = "776.26";
var stockholm = "776.26";
var zurich = "776.26";
var taiwan = "776.26";
var toronto = "776.26";
var vienna = "776.26";
var argentina = "776.26";
var brazil = "776.26";
var chile = "776.26";
var istanbul = "776.26";
var jakarta = "776.26";
var kuala = "776.26";
var mexico = "776.26";
var philippines = "776.26";
var shangai = "776.26";
var thailand = "776.26;

---

but it is still not working. (you may check on the page)

am I missing something?

thank you for your time.

beetle
10-29-2002, 11:21 PM
You cannot put any scripting within the block of a script tag that loads an external file. Besides...the document.write() command has to take place in the document at the point you need it written...

so, include the file once...in the <HEAD> and use document.write commands in their own <script> blocks in the page to write your values...

ssskaya
10-30-2002, 12:58 AM
ok....

-------------right in the <head> is:

<script src="http://www.fiscalstudy.com/values.js"></script>

------------and right in the place for the value is:

<script>document.write(djia);</script>


----------and the .js file is exactly the same as before.


but still not working.

there must be something else I am missing.

thanks again. I appreciate it.

glenngv
10-30-2002, 01:11 AM
what's the error message?

ssskaya
10-30-2002, 02:01 AM
I do not have error messages.

it just doesnt show up on the page. it is blank.

it is already uploaded. you can see it at:

www.fiscalstudy.com/major.html

glenngv
10-30-2002, 03:21 AM
there are errors, "Expected identifier". and as a consequence of that, another error appears, "djian undefined". Maybe your browser setting for script error is turned off.

anyway here's the solution:

var thailand = "776.26";

you missed the closing quote.

ssskaya
10-30-2002, 05:18 AM
dear glenn,

yes you are right. error messages were turned off.

but after closing the quote, it still gives the same two errors. I started thinking that it may be sth that has to do with the .js file.

because it somehow cannot define djia.

glenngv
10-30-2002, 06:27 AM
try renaming the new variable:

var new = "776.26";

it is a keyword in javascript

ssskaya
10-30-2002, 06:49 AM
tried that.

no difference.

so you are sure that, in the .js file, just listing the variables as: var a = "123"; var b = "456";... and so on is all that it takes, right? there should be no functions or document.write() commands, right?

glenngv
10-30-2002, 06:53 AM
yes correct.

but why did you put new in all your variables?!

var new djia = "7286.27";
var new nasdaq = "1114.11";
var new sp = "776.26";

there should be no new there?
who told you to put it?

ssskaya
10-30-2002, 06:59 AM
oh!

I told you were talking about something else!

now I got it! you mean the variable I use for new zealand may be causing a conflict!

looks quite silly, I know :)

ssskaya
10-30-2002, 07:01 AM
man,.. you're beautiful!

IT WORKS NOW!

Thanks a million!