1

I've had a lot of help from a number of you over the past week or so with my first effort programming an application from the ground up. Thank you from the bottom of my code monkey heart!

I need to add a points calculation function to my fantasy football scoring app. Below is the results page, with the drop downs for the calculation function in place (but without the actual calculating functionality):

enter image description here

The user will be able to select how many points each stat (or increment of a stat) is worth and then click the Get Scores button and the totals will show up in the TFP column (the tan column).

So using the settings shown in the screenshot, the formula would be:

1(Pass_Yds / 20) + (4 * Pass_TD) + 1(Rush_Yds / 10) + (6 * Rush_TD) + (0 * Int) = TFP

I've looked at the jQuery calculator plugin, which I assume is what I'll need to use, but I have no idea how to do the type of complex (for me at least) calculation shown above.

user229044
  • 232,980
  • 40
  • 330
  • 338
Cynthia
  • 5,273
  • 13
  • 42
  • 71
  • Is there an easier way to do what I need than using the jquery calculator plugin? I'm open to suggestions. – Cynthia May 23 '12 at 02:37

2 Answers2

2

I have the same issue where my client ask me to build some complex calculation form, so I decide to write my own plugin you can found here https://github.com/ikhsan017/calx

just need to write the calculation formula into the data-formula attribute, and assign $ char to each variable

1(Pass_Yds / 20) + (4 * Pass_TD) + 1(Rush_Yds / 10) + (6 * Rush_TD) + (0 * Int)

assume that you have all input element with associated id

<form id="test">
    Pass Yds : <input id="Pass_Yds" /><br />
    Pass TD : <input id="Pass_TD" /><br />
    Rush Yds : <input id="Rush_Yds" /><br />
    Rush  TD : <input id="Rush_TD" /><br />
    Int : <input id="Int" /><br />
    <!--- skip -->
    Result : <input id="TFP" data-formula="1*($Pass_Yds / 20) + (4 * $Pass_TD) + 1*($Rush_Yds / 10) + (6 * $Rush_TD) + (0 * $Int)" />
</form>

Hope this plugin useful :)

ikhsan
  • 373
  • 2
  • 11
0

Depending on the specific html. I'm not sure about how you are using the points / yds stuff but the following will get you started:

$('#btnUpdate').click(function() {  // get this all after user clicks button

var ptspassyrds = parseInt($('#ptspassyrds').val());
var ptspassyrdsamt = parseInt($('#ptspassydsamt').val());

$('#stats tr').each(function() {
  var passyds = parseInt($('td:eq(2)',this).text());
  var paddtds = parseInt($('td:eq(3)',this).text());
  var interceptions = parseInt($('td:eq(4)',this).text());
  // etc
  var tfp = (ptspassyrds / ptspassyrdsamt) + (4*passtds); //etc depending on exactly what you need to do
  $('td:eq(8)').text(tfp);
});

});
lucuma
  • 18,247
  • 4
  • 66
  • 91
  • Interesting... except that the 20 and the 4 aren't pre-defined. Those numbers will be whatever the user selects in the drop downs. – Cynthia May 23 '12 at 03:01
  • I just updated right before your comment. I wasn't exactly sure how you were using those but I did put an example of using some values from inputs. You just need to get their values and use them in the equation but you should get the values outside the each loop. – lucuma May 23 '12 at 03:01