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

Thread: Please Help Me

  1. #1
    New Coder
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Please Help Me

    I have this code, but when I get to the last package, it returns a value of 0

    I really can't understand what I am doing wrong. Please help me if you can. I aim to add another 4 categories to this calculator.

    Code:
    <html>
    <head></head>
    <body>
    <form name=theForm onclick=getTotal() >
    <div class="item">
    <h1>Wedding Package:</h1>
    </div>
    <input name="WP" type="radio" checked value="399~~Package1"> Package 1 <br>
    <input name="WP" type="radio" checked value="499~~Package2"> Package 2 <br>
    <input name="WP" type="radio" checked value="599~~Package3"> Package 3 <br>
    <input name="WP" type="radio" checked value="699~~Package4"> Package 4 <br>
    <input name="WP" type="radio" checked value="799~~Package5"> Package 5 <br>
    <input name="WP" type="radio" checked value="899~~Package6"> Package 6 <br>
    <input name="WP" type="radio" checked value="999~~Package7"> Package 7 <br>
    <input name="WP" type="radio" checked value="1000~~Package8"> Package 8 <br>
    <br><br>
    
    </form>
    
    <span id=totalspan>
    </span>
    </body>
    
    <script type=text/javascript>
    function getTotal(){
    var form=document.theForm;
    var inputs=form.getElementsByTagName('input');
    var length=inputs.length;
    var total='0';
    
    for(i=0;i<length-1;i++){
    if(inputs[i].type=='radio'){
    var checked=inputs[i].checked?1:0;
    if(checked){
    var value=inputs[i].value.split("~~")[0];
    total-=-value;
    }
    }
    }
    document.getElementById('totalspan').innerHTML="<strong>Total price will be: </strong>"+total
    }
    
    </script>
    
    
    </html>
    Last edited by signman; 12-26-2010 at 07:16 PM.

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Change this.
    Code:
    total-=-value;
    To this.
    Code:
    total = value[0];
    And also change the onclick on the form tag to onsubmit and add a submit button or add the onclick to each of the radio buttons.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    New Coder
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you so much


  •  

    Posting Permissions

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