greenshoes
09-27-2002, 09:13 AM
Hello, Apologies first this is no doubt simple,I am a newbie.
I have cobbled together this script to add some user input numbers from a form and display the sum of the numbers in a text field in the form. When I use the + character the numbers are treated as a string but when I use -,* or / the calculation is performed. How can I get the script to add 2 numbers together simply:
<SCRIPT language=JavaScript>
function calc(a,b) {
a = document.frm1.a.value;
b = a+document.frm1.b.value; insert *, - or / on this line it works but with + it doesn't
document.frm1.total1.value = b;
}
</SCRIPT>
</head>
<body bgcolor="#FFFFFF"
<FORM name=frm>
<TABLE border=0>
<TR>
<TD> <INPUT name=a> + <INPUT size=5 name=b>?</TD>
<TD> = <INPUT name=total></TD>
<TD><INPUT onclick=calc() type=button value=Calculate></TD>
<TD> <INPUT type=reset value=Reset></TD></TR></TABLE></FORM>
</body>
I have cobbled together this script to add some user input numbers from a form and display the sum of the numbers in a text field in the form. When I use the + character the numbers are treated as a string but when I use -,* or / the calculation is performed. How can I get the script to add 2 numbers together simply:
<SCRIPT language=JavaScript>
function calc(a,b) {
a = document.frm1.a.value;
b = a+document.frm1.b.value; insert *, - or / on this line it works but with + it doesn't
document.frm1.total1.value = b;
}
</SCRIPT>
</head>
<body bgcolor="#FFFFFF"
<FORM name=frm>
<TABLE border=0>
<TR>
<TD> <INPUT name=a> + <INPUT size=5 name=b>?</TD>
<TD> = <INPUT name=total></TD>
<TD><INPUT onclick=calc() type=button value=Calculate></TD>
<TD> <INPUT type=reset value=Reset></TD></TR></TABLE></FORM>
</body>