SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating Total of Order

    I have a order form that I need to 1) Calculate the total number of items from 6 different select boxes and 2) serve an alert when order total is not a multiple of 6.

    This is the code I have so far and it is not working.

    Select Box:
    <select name="gift_pak_qty_01" class="form_label" onChange="updateTotal();">
    <select name="gift_pak_qty_02" class="form_label" onChange="updateTotal();">
    <select name="gift_pak_qty_03" class="form_label" onChange="updateTotal();">
    <select name="gift_pak_qty_04" class="form_label" onChange="updateTotal();">
    <select name="gift_pak_qty_05" class="form_label" onChange="updateTotal();">
    <select name="gift_pak_qty_06" class="form_label" onChange="updateTotal();">

    Javascript:
    function updateTotal() {
    var totalQty = (document.orderForm.gift_pak_qty_01.value -0) + (document.orderForm.gift_pak_qty_02.value -0) + (document.orderForm.gift_pak_qty_03.value -0) + (document.orderForm.gift_pak_qty_04.value -0) + (document.orderForm.gift_pak_qty_05.value -0) + (document.orderForm.gift_pak_qty_06.value -0);

    if (totalQty == !"6" OR "12" OR "18" OR "24" OR "30" OR "36") {
    alert('You Must Order in Multiples of Six');
    return false;
    }

    return true;

    }



    I can't seem to get the correct total and I have no idea how to check if the value of total is 6, 12, 18, 24, 30 or 36.

    Any assitance would be greatly appreciated. I really need to get this working before Monday morning.

    Thanks,
    Russell

  2. #2
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      
    <script type="text/javascript">
    function updateTotal() {
    var i=1, s, arr=[];
    while(s=document.orderForm.elements["gift_pak_qty_0"+(i++)]) arr[arr.length]=s.value;
    var total=eval(arr.join('+'));
    alert(total);
    if(total&#37;6!=0) { alert('You Must Order in Multiples of Six'); return false; }
    return true;
    }
    </script>
    <body>
    <form name="orderForm">
    <select name="gift_pak_qty_01" class="form_label" onChange="updateTotal();">
    <option value="6">6</option>
    <option value="12">12</option>
    </select>
    <select name="gift_pak_qty_02" class="form_label" onChange="updateTotal();">
    <option value="6">6</option>
    <option value="7">7</option>
    </select>
    <select name="gift_pak_qty_03" class="form_label" onChange="updateTotal();">
    <option value="6">6</option></select>
    <select name="gift_pak_qty_04" class="form_label" onChange="updateTotal();">
    <option value="6">6</option></select>
    <select name="gift_pak_qty_05" class="form_label" onChange="updateTotal();">
    <option value="6">6</option></select>
    <select name="gift_pak_qty_06" class="form_label" onChange="updateTotal();">
    <option value="6">6</option></select>
    </form>
    The Time Through Ages
    1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for taking the time to respond, but the code does not owrk on the page I have.

    I added your code to a live page here: http://www.woodallcreative.com/proof...der-online.php

    The second Javascript alert works when a required filed is left empty, but the form still submits even when the Qty selection is left empty.

  4. #4
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My English is not very well. You try this, if I understand you.

    if(total!=6 || total!=12 || total!=18 || total!=24 || total!=30 || total!=36) {
    alert('You Must Order in Multiples of Six'); return false;
    }
    The Time Through Ages
    1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can still submit the page without the alert message being triggered.

  6. #6
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:
    if( (total>5 && total&#37;6!=0) || total<6)

    You should not write OR instead of || .

    If it does not do what you wanted, I and you must study this subject
    Last edited by muazzez; Apr 20, 2008 at 08:17.
    The Time Through Ages
    1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.

  7. #7
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is still allowing me to submit an order without verifying the order placed is either 6, 12, 18, 24, 30 or 36.

    http://www.woodallcreative.com/proof...nfirmation.php

    Thank you for your help.


Bookmarks

Posting Permissions

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