Javascript Input Checkbox Calculator help

Discussion in 'Programming' started by tdd1984, Sep 4, 2007.

  1. #1
    I need something to add up the values from the input checkboxes and show it at the bottom the value, preferable like in span text type deal. I'm famaliar with php, but I can not get this to work.

    Could any one help me out here?

    Take a quick look at the bottom
    <input value="554.98" type="checkbox" onclick="calc(this.value)">
    <input value="234.98" type="checkbox" onclick="calc(this.value)">
    <input value="5534.98" type="checkbox" onclick="calc(this.value)">

    I have 7 input checkboxes, what I need them to do is add the value from every one, and be able to show it at the bottom of the page and put it into a url. I remember doing it awhile back using a span, but I'm not quite sure or I don't quite remember how to do it. So basically the user comes in checks the items he wants the value updates at the bottom in text form, and this will also be inserted into a url when the submit button is selected.

    Can any one help me with this?
     
    tdd1984, Sep 4, 2007 IP
  2. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Not sure if this is exactly what you are looking for ... but might help.

    <script>
    function calc(val){

    var totalval = document.getElementById('total').innerHTML * 1;
    document.getElementById('total').innerHTML = (totalval + parseInt(val));

    }
    </script>


    <input value="554.98" type="checkbox" onclick="calc(this.value)">
    <input value="234.98" type="checkbox" onclick="calc(this.value)">
    <input value="5534.98" type="checkbox" onclick="calc(this.value)">



    <p id="total"></p>

    Basically as you click off the checkboxes the value is changed in the <p> tag. You can also change that <p> tag to a <span> or a <div>
     
    rederick, Sep 4, 2007 IP