#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    7
    Rep Power
    0

    Trying to add two values from different javascript arrays


    I am deriving two different values from these scripts.

    Script #1...

    Code:
    //JS for Potential Gen Ed TOC
    $(function($) {
        $('#CourseMenu select').change(function() {
            var sum = 0;
            $('#CourseMenu select').each(function(idx, elm) {
                sum += parseFloat(elm.value, 10);
            });
    
         $('#total_potential').html(Math.min(sum,72).toFixed(2));
        });
    });
    
    
    //JS for Potential Gen Ed TOC from Electives only
    $(function($) {
        $('#CourseMenu_Electives select').change(function() {
            var sum = 0;
            $('#CourseMenu_Electives select').each(function(idx, elm) {
                sum += parseFloat(elm.value, 10);
            });
    
         $('#total_potential').html(Math.min(sum,33).toFixed(2));
        });
    });
    
    
    //JS for Potential Money Saved
    $(function($) {
        $('#CourseMenu select').change(function() {
            var sum = 0;
            $('#CourseMenu select').each(function(idx, elm) {
                sum += parseInt(elm.value, 10)*561;
            });
    
         $('#total_money').html(Math.min(sum,40392).toFixed(0))
        });
    });
    
    
    //JS for Potential Class Time Saved
    $(function($) {
        var sum = 0;
        $('#CourseMenu :checkbox').click(function() {
            sum = 0;
            $('#CourseMenu :checkbox:checked').each(function(idx, elm) {
                 sum += parseInt(elm.value, 10);
            });
    
            $('#total_time').html(sum); //Displays resulting amount of credits
    $('#total_time').html($('#CourseMenu :checkbox:checked').length*5); //Displays resulting time saved in weeks
    
        });
    });
    I'd like to pull the data from both of these and have the result display in the following HTML...

    Code:
       <p><fieldset id="PotentialTOC">
          <legend style="font-weight: bold; font-size: 140%;">Potential TOC Evaluation Results</legend>
    
          <div id="Results" style="text-align:left; font-family: 'Century Gothic', Gadget, sans-serif; font-size:14px;"><br />
            <div>
              <h2><span id="span"></span>
            Potential Gen Ed TOC:&nbsp;&nbsp;<span id="total_potential"></span>
            <br />
            Potential Money Saved: $<span id="total_money"></span>
            <br />
            Potential Class Time Saved:&nbsp;&nbsp;<span id="total_time"></span> weeks
    </fieldset></p>
    Here's a jsfiddle (http://jsfiddle.net/jlnewnam/fhL3s/) to show what I've done so far... I can't transfer more than 33 elective credits and no more than 72 credits overall. I have the scripts laid out well, but again, need them combined to spit out one value.

    Does that make sense?
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,158
    Rep Power
    183
    Instead of using the .html() API; try using the .append() API. That way you get the results of both of your forms; inserted into your html elements and format the output of your form data (in your .append() API), so that the data output, in your html element(s), appears the way you would like it to appear. This would probably be the easiest approach, to what your wanting to do.

IMN logo majestic logo threadwatch logo seochat tools logo