Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Addition Glitch

    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

    }
    </Script>

    heres the snippet of code where this function is called
    <tr>
    <td><center>
    <input name="Selected<%response.write Prod %>" type="radio" value="Yes" onClick="SPKUpdate()">
    Yes
    <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??

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use either the parseFloat, parseInt or Number object methods or simply multiply both values by 1 to convert them from strings to numbers.

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

    .....Willy

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't forget to read the same reply at your cross-post here.

    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •