PDA

View Full Version : Different image depending on the number value


ssskaya
12-24-2002, 11:19 PM
On the page: http://www.fiscalstudy.com/major.html , I have the stock indices on one column, and the "change" from yesterday on the other column.

I will add there a new column which will have only a up or down arrow depending on the "change".

I want the javascript to:

- show the up arrow when the "change" value is positive.
- show the down arrow when the "change" value is negative.
- show " - " when the "change" is 0.

What is the right script for that?

Thanks a lot!

ez4me2c3d
12-25-2002, 06:27 AM
I did a little digging and saw where your values were coming from. turns out they are not numbers but a string, so that made this easy.

place this function in your head section
function upDown(which) {
if (x.indexOf("+") == -1) {
if (x.indexOf("-") == -1) {
return '<img src="dash.gif">';
} else {
return '<img src="down.gif">';
}
} else {
return '<img src="up.gif">';
}
}

place this in every spot you want the arrows/dash to appear
<script>document.write(upDown(changeValue));</script>

changeValue would be replaced by the name of the variable holding the change for that item (ie hangc for Hang Seng)

ssskaya
12-25-2002, 04:24 PM
dear anthony,

I have done that.

But the error says: "x" is undefined.

what should I do?

(You can see it yourself on the page).

ez4me2c3d
12-25-2002, 04:31 PM
my bad, i was testing under variable x but just forgot to switch it back.. change all "x"'s to "which" like so:
function upDown(which) {
if (which.indexOf("+") == -1) {
if (which.indexOf("-") == -1) {
return '<img src="dash.gif">';
} else {
return '<img src="down.gif">';
}
} else {
return '<img src="up.gif">';
}
}

ssskaya
12-25-2002, 05:33 PM
Thanks man,

I appreciate it!!

ez4me2c3d
12-26-2002, 02:20 AM
you're welcome