Click to See Complete Forum and Search --> : Subtracting


elwell
08-07-2003, 05:18 PM
I want have a varible named "money" and the intial value is 500. Then I want the have whatever is typed in the "amount" textbox to be multiplyed by 12 . Then subtract whatever money * 12 is from the 500. Then money is set to its new number and if more is subracted later on it wont subtract from 500 instead it will subtract from the new "money". It tried to do part of it but it always says that money is zero even though it shouldn't be.

<html><head><title>Current Stocks</title>
<script type="text/javascript">
money = new Number
money = 500 - document.getElementById('amount').value
function addUp() {
alert("You Just Spent $"+document.getElementById('amount').value *12+". You Have $" +money +" Left Over");
}
</script>
<style type="text/css">
.links {position: absolute; top:440px; left:290px; font-family: Trebuchet MS, sans-serif; font-weight: normal; font-size:12}
</style>
</head>
<body>
<span style="position: absolute; top:30px; left:240px; font-family: Trebuchet MS, sans-serif; font-size: 40">Current Stocks</span>
<span class="links"><a href="about.html">About</a> | <a href="dowjon.html">Home</a> | <a href="contact.html">Contact Us</a> | <a href="faq.html">FAQ</a></span>

<span style="position: absolute; top:200px; left:0px; font-family: Trebuchet MS, sans-serif; font-size: 12"><marquee>

<font color="green" size="5">ABHC + 5&nbsp=&nbsp16</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font color="red" size="5">CCHHY -3&nbsp=&nbsp20</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font size="5">CHRIS&nbsp=&nbsp40</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font color="green" size="5">DADO +46&nbsp=&nbsp5</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font color="red" size="5">JON -3&nbsp=&nbsp67</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font size="5">LIZ &nbsp=&nbsp45</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font size="5">MOM &nbsp=&nbsp98</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

<font color="red" size="5">ZYTY -3&nbsp=&nbsp23</font>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

</span>

</marquee>
<span style="position: absolute; top:120px; left:40px; font-family: Trebuchet MS, sans-serif; font-size: 12">
<form name="stockform">
The DOW JON STOCK EXCHANGE is at an all-time high.<br />Buy DOW JON Stock Today.<br />
Tag:<input name="tag" type="textbox" size="7" /><br />
How Many Shares:<input name="amount" id="amount" type="textbox" size="4" /><br />
<a href="javascript:addUp()">Buy</a><br />
(You cant buy or sell stocks if your not <a href="dowjon.html">logged in</a>)
</form>
</span>

</body>
</html>

AdamBrill
08-07-2003, 05:26 PM
Try this:<html><head><title>Current Stocks</title>
<script type="text/javascript">
money = 500;
function addUp() {
money -= parseInt(document.getElementById('amount').value)*12;
alert("You Just Spent $"+document.getElementById('amount').value *12+". You Have $" +money +" Left Over");
}
</script>
<style type="text/css">
.links {position: absolute; top:440px; left:290px; font-family: Trebuchet MS, sans-serif; font-weight: normal; font-size:12}
</style>
</head>
<body>
<span style="position: absolute; top:30px; left:240px; font-family: Trebuchet MS, sans-serif; font-size: 40">Current Stocks</span>
<span class="links"><a href="about.html">About</a> | <a href="dowjon.html">Home</a> | <a href="contact.html">Contact Us</a> | <a href="faq.html">FAQ</a></span>

<span style="position: absolute; top:200px; left:0px; font-family: Trebuchet MS, sans-serif; font-size: 12"><marquee>
<font color="green" size="5">ABHC + 5 = 16</font>
<font color="red" size="5">CCHHY -3 = 20</font>
<font size="5">CHRIS = 40</font>
<font color="green" size="5">DADO +46 = 5</font>
<font color="red" size="5">JON -3 = 67</font>
<font size="5">LIZ = 45</font>
<font size="5">MOM = 98</font>
<font color="red" size="5">ZYTY -3 = 23</font>
</span>

</marquee>
<span style="position: absolute; top:120px; left:40px; font-family: Trebuchet MS, sans-serif; font-size: 12">
<form name="stockform">
The DOW JON STOCK EXCHANGE is at an all-time high.<br />Buy DOW JON Stock Today.<br />
Tag:<input name="tag" type="textbox" size="7" /><br />
How Many Shares:<input name="amount" id="amount" type="textbox" size="4" /><br />
<a href="javascript:addUp()">Buy</a><br />
(You cant buy or sell stocks if your not <a href="dowjon.html">logged in</a> )
</form>
</span>

</body>
</html>

elwell
08-07-2003, 05:29 PM
Thank You it works well. You made a mistake though:
you: href="java script:addup()"
correct: href="javascript:addup()"

AdamBrill
08-07-2003, 05:34 PM
If you go up and look at your post, you will see the same thing. ;) The forums put the space in there, not me. :) And the true "right" way of doing it would be this:

<a href="#" onclick="addUp();">Buy</a>

:cool:

pyro
08-07-2003, 10:38 PM
Not to be picky, but... :D

The actual correct way would be this:

<a href="#" onclick="addUp(); return false;">Buy</a>
or, perhaps even better, if the link will do nothing for those without javascript enabled:

<script type="text/javascript">
document.write('<a href="#" onclick="addUp(); return false;">Buy</a>');
</script>