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
    Feb 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    addition not concatination!!

    I've never used JS before, after reading around here and searching on google I came up with a script that takes the value of a radio button and adds it to the value of the next radio button.

    All my code seems logical except instead of adding the two numbers together the code is concatenating the two.


    <script>
    <!-- Begin
    var understands, coverage, detail, logical;
    var average;
    function getRadios(what){


    j=what.understands.length; //alert(j)
    for (i=0; i<j; i++)
    {
    if(what.understands[i].checked) var average = what.understands[i].value
    }

    for (i=0; i<j; i++)
    {
    if(what.coverage[i].checked) var average = average + what.coverage[i].value
    }

    what.grade.value = (average)
    }
    // End -->
    </script>

    Where is my fundamental mistake? Thanks.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    you need to use parseInt or parseFloat

    example would be

    intVar = parseFloat(document.formName.elementName.value) + parseFloat("123");

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    painless, thank you


  •  

    Posting Permissions

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