#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    579
    Rep Power
    51

    Change in one JavaScript, updating another?


    Hi:

    I have an order form which allows the user to enter a quantity of items on multiple lines. The unit prices for the line items is different depending on whether a customer is a "member" or not. The "non-member" customer can also elect to add "membership cost" to his/her order, in which case s/he will be given member pricing on the line items s/he selects.

    The problem is, if s/he is not a member and selects a quantity of a line item, s/he is given the non-member pricing. If s/he the goes back and selects "yes, add membership", the line item pricing does not update the unit price UNLESS s/he re-enters the quantity.

    The "Add Membership" script looks like this:
    Code:
    <script type=\"text/javascript\">
    function dropdownMbr(value){
    var curr_member = \"$member\";
    document.getElementById(\"mbr_add\").innerHTML = value;
    var addm = document.getElementById(\"mbr_add\").innerHTML;
    // alert(addm);
    document.getElementById('memSelect').innerHTML = addm; 
    }
    </script>
    The line item calculation script looks like this:
    Code:
    <script type=\"text/javascript\">  
    $('.unitCount').keyup(function(e){ 
    var mbr_add = Number(document.getElementById(\"mbr_add\").innerHTML);
    var curr_mbr = \"$member\";
    if(curr_mbr == \"yes\" || mbr_add >0){
    var memType = \"member\";
    }else{
    var memType = \"standard\";
    }
    var unitCount = $(this).val(); 
    var unitSubId = $(this).attr('data-id'); 
    var unitPrice = {'standard': +$(this).attr('data-standard'), 'member': +$(this).attr('data-member'), 'joining': +$(this).attr('data-member')};  
    // var memType = document.getElementById(\"memSelect\").value; 
    var memFee = mbr_add;
    // alert (\"Mbr Fee: \" + memFee);		
    var grandTotal = 0.00; 
    var unitSub = (unitCount * unitPrice[memType]);
    document.getElementById('unitPriceDisp'+unitSubId).innerHTML = '$'+unitPrice[memType].toFixed(2); 
    document.getElementById('unitSubDisp'+unitSubId).innerHTML = '$'+unitSub.toFixed(2); 
    document.getElementById('unit_price['+unitSubId+']').value = unitPrice[memType].toFixed(2); 
    document.getElementById('subttl['+unitSubId+']').value = unitSub.toFixed(2); 
    $('.subVal').each(function() { grandTotal += +this.value }); 
    if(memFee > 0) {
    grandTotal += memFee; 
    document.getElementById('MemberFeeDisp').innerHTML = '$'+memFee.toFixed(2);
    document.getElementById('mbrFee').value = memFee.toFixed(2); 
    }
    document.getElementById('GrandTotal').innerHTML = '$'+grandTotal.toFixed(2); 
    }); 
    </script>
    How can I get the Line Items to update when the "dropdownMbr" function changes. Or, more simply, How can I at least reset all line items to zero when "dropdownMbr" changes?

    Any suggestions greatly appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    579
    Rep Power
    51
    Sorry all... this was not a well formulated question...

    I did a little research and some trial and error and found that I should simply modify the first script with the relevant document.getElementById's and it worked fine

IMN logo majestic logo threadwatch logo seochat tools logo