score:1

Accepted answer

you can put the code that draws the chart in a function and call that function on both the $(document).ready and $("#submit-btn").click event, like this:

function drawchart() {
  var outputyearly = $('#outputyearly');
  var amount = parseint($('#amount').val().replace(/,/g, ''), 10);
  var rate = parsefloat($('#rate').val(), 10);
  var term = parsefloat($('#term').val(), 10);

  //destroy the dougnut chart here, not sure how it's accessible, but it won't work through window.onload

  var ctx = document.getelementbyid("mychart").getcontext("2d");

  new chart(ctx, {
      type: 'doughnut',
      data: data,
      options: options
  });
}

$(document).ready(function() {
  drawchart();
  $("#submit-btn").click(function (e) {
     e.preventdefault();
     drawchart();
   });
 });

note that $(document).ready already imposes the code inside of it to be executed when the page is done, so putting a window.onload inside of it won't make any difference.


Related Query

More Query from same tag