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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automatic Total updates

    Hi, I admit from the start, I'm not very good with JS, I've used it a few times over the years, but mostly readymade scripts that I can just link to a website and use.

    Anyway, I need something somewhat specific and I don't know where to find such a code or even if I can modify the one I have found to do what I need. What I need is to be able to update totals on the page as things are changed, but I'm not talking about one total. What I have is a list of spare parts with a quantity box next to them, when someone changes the quatity the price for that part needs to update as well as the total price AND a sum that is an allocated amount minus the total (so they can see how much of their allocation they have left).

    So far, all I've managed to find is a script that will update just the final total (http://www.mcfedries.com/JavaScript/OrderTotals.asp), but as you can see, that's not that helpful. I've sat and stared at the code and while I can say what things do what, I wouldn't know where to start in changing it.

    Hope someone can help!
    Thanks

    Form cap: http://img38.imageshack.us/img38/8118/partlist.png

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,130
    Thanks
    38
    Thanked 504 Times in 498 Posts
    You should be able to do what you want with JS
    but we will not create the HTML for you.

    Write the form and enter default field values for your project.
    Then we can see what needs to be altered to perform
    the task you want to do.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I included a screen capture of the form - it's already written using html/asp as all the prices are in a database and that's where the submitted data will go too.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    There is a delicate balance between asking for help with a specific Javascript problem, and getting others to do your paid or commercial work for you. You seem to be veering towards the latter. Here is a skeleton of what you want. If you are unable to take it further then I suggest you pay for professional assistance. Presumably you would not attempt to service or repair a machine or appliance without any experience or understanding of how it worked.


    Code:
    <html>
    <head>
    <body>
    
    <form name = "myform">
    4redf Part Name $13.99 <input type = "text" size = "6" name = "qty1" value = 0 onchange = "calc()"> <input type = "text" size = "6" name = "c1" value = 0 readonly><br>
    4rgrr Part Name $17.99 <input type = "text" size = "6" name = "qty2" value = 0 onchange = "calc()"> <input type = "text" size = "6" name = "c2" value = 0 readonly><br>
    456erth Part Name $3.99 <input type = "text" size = "6" name = "qty3" value = 0 onchange = "calc()"> <input type = "text" size = "6" name = "c3" value = 0 readonly><br>
    34terg Part Name $7.99 <input type = "text" size = "6" name = "qty4" value = 0 onchange = "calc()"> <input type = "text" size = "6" name = "c4" value = 0 readonly"><br>
    <br>
    Total Cost <input type = "text" name= "tot" size = "6" value = 0 readonly><br>
    Balance Remaining <input type = "text" name= "bal" value = 5000 size = "6" readonly>
    </form>
    
    <script type = "text/javascript">
    
    function calc() {
    
    var q1 = parseFloat(document.myform.qty1.value);
    if (isNaN(q1) || q1 <0) {
    alert ("Invalid value - you must enter a postive number for this part 4redf");
    document.myform.qty1.value = "";
    return false;
    }
    
    var q2 = parseFloat(document.myform.qty2.value);
    if (isNaN(q2) || q2 <0) {
    alert ("Invalid value - you must enter a postive number for this part 4rgrr");
    document.myform.qty2.value = "";
    return false;
    }
    
    var q3 = parseFloat(document.myform.qty3.value);
    if (isNaN(q3) || q3 <0) {
    alert ("Invalid value - you must enter a postive number for this part 456erth");
    document.myform.qty3.value = "";
    return false;
    }
    
    var q4 = parseFloat(document.myform.qty4.value);
    if (isNaN(q4) || q4 <0) {
    alert ("Invalid value - you must enter a postive number for this part 34terg");
    document.myform.qty4.value = "";
    return false;
    }
    
    var cost1 = 13.99 * q1;
    var cost2 = 17.99 * q2
    var cost3 = 3.99 * q3
    var cost4 = 7.99 * q4;
    
    var t = cost1 + cost2 +cost3 + cost4; 
    var b = 5000 - t;
    
    document.myform.c1.value = cost1.toFixed(2);
    document.myform.c2.value = cost2.toFixed(2);
    document.myform.c3.value = cost3.toFixed(2);
    document.myform.c4.value = cost4.toFixed(2);
    
    document.myform.tot.value = t.toFixed(2);
    document.myform.bal.value = b.toFixed(2);
    }
    
    </script>
    
    
    
    </body>
    </html>
    You will note that a good part of the code is validation.


    Next we have someone following in her father's footsteps by becoming the first Asian female councillor in Rushmoor. - BBC Surrey
    Last edited by Philip M; 06-16-2010 at 08:09 PM.

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I wasn't looking for someone to do it for me, just to give me more information about what to change where and how - unlike another forum I've posted this question too where they didn't take in the fact that I've never written JS in my life and the only help I got was "add an onblur event to the inputs that loops through the form calculating each individual item price and keeping a running total" which meant nothing to me!

    On the other end, I come here and get treated like a complete idiot for mentioning that I'm not sure what I'm doing.

    Either way, you've been more helpful than anyone else.
    Thank you!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    As I said, presumably you would not attempt to service or repair a machine or appliance without any experience or understanding of how it worked. But you should be aware that this forum is not a free coding service.

  • #7
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I never expected it to be a place for free coding, i expected a place to find someone to teach me what things did and how to adjust it. I learn by doing, I've done so my whole life, I'm not afraid of testing to see how something works.

    But if I'm going to be judged for asking for help, then I won't come back.


  •  

    Posting Permissions

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