View Full Version : Simple Addition Glitch

Dean Forant
04-23-2004, 03:22 PM
Hey Group.. I have a small problem it seems like its really simple..

I have a Form Field that puts a base price from a Mysql database..

now theres a Radio Button that shows up for an additional option..

I tried writing a function to take the base price of the Form field and add 80 to it and then in the radio button I call the function with an onClick Event. for the Yes Radio Button..

whats happening is instead of adding 80 to the base price its conacticating them together.. I know the + is used for both Addition and Conecticating strings together..

heres a copy of my code..

The Function
<Script Language="JavaScript">
function SPKUpdate()
var SPKBase=document.Options.PriceSPK.value;
var InboardAdder = 80;
var SPKTotal = SPKBase+InboardAdder;
document.Options.PriceSPK.value = SPKTotal


heres the snippet of code where this function is called
<input name="Selected<%response.write Prod %>" type="radio" value="Yes" onClick="SPKUpdate()">
<input name="Selected<%response.write Prod %>" type="radio" value="No" checked>
No </center></td>

don't mind the ASP Generated Names of the form.. thats setting the name of the form element based on the Product code from the database.. and it works..

any suggestions??

Willy Duitt
04-23-2004, 03:43 PM
You can use either the parseFloat, parseInt or Number (http://www.htmlgoodies.com/js-ref/part4.html) object methods or simply multiply both values by 1 to convert them from strings to numbers.

eg: var SPKTotal = (SPKBase*1)+(InboardAdder*1);


Willy Duitt
04-23-2004, 05:06 PM
Don't forget to read the same reply at your cross-post here (http://www.webxpertz.net/forums/showthread.php?p=155373#post155373). http://www.codingforums.com/images/smilies/mad.gif