[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Nebie Question - Addition vs. Concatenation
At 09:45 AM 2/22/96 GMT, you wrote:
>On Wed, 21 Feb 1996 19:34:11 -0500, you wrote:
>
>>Hi everyone.
>>
>>I;ve just started learning JavaScript, so I decided that my first project
>>would be a simple four-function calculator. It works great except for
addition.
>>
>>When I add 5 + 10, I get 510. For some reason, the procedure treats my
>>numbers as strings, while in the other three operations, it works fine.
>
>
>Use 1 * 5 +10, you'll get 15...<G>
Still didn't work. I've included the relevant code this time.
When I click on the button to add, this.form is sent to the function
addition, which takes two fields with numbers. I add them, but it
concatenates them. I took your suggestion and made it (1* # + #) as shown
below, but it still doesn't work.
Any more suggestions out there??? Thanks in advance,
David Gotz
THe url is http://zion.gt.ed.net/calc.html
---------Included text---------
function addition(form) {
form.hiddennum.value = eval("1 * form.hiddennum.value +form.currentnum.value")
equals(form)
}
function equals(form) {
form.currentnum.value = eval(form.hiddennum.value)
}
// end hiding contents from old browsers -->
</SCRIPT>
<BODY>
<FORM>
<INPUT TYPE="BUTTON" VALUE=" + " onClick="addition(this.form)">
---------End of Included Text---------
+-------------------------------------------------------------------------+
| David H. Gotz Georgia Tech 331252 Georgia Tech Station |
| (404) 206-8032 gotz@cc.gatech.edu Atlanta, GA 30332-1370 |
| http://zion.gt.ed.net/ http://www.cc.gatech.edu/people/home/gotz/ |
| CS Major-If hiring summer interns, check out my resume on my home page! |
+-------------------------------------------------------------------------+
--------------------------------------------------------------------
This message came from the mailing list javascript. For help using the
mailing list software, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.