Eduardo Borba
Eduardo Borba

Reputation: 1

JS: calling a function from another JS file

I want to return some values in the dda.js that have been modified in translacao.js. I want to return this values and execute the dda.js by the translacao.js file

$(document).on('click', '#trans', function () {
  var tx = parseInt($('#tx').val());
  var ty = parseInt($('#ty').val());
  translation(tx, ty);
});

function translation(tx, ty) {
  x1 = x1 + tx;
  y1 = y1 + ty;
  x2 = x2 + tx;
  y2 = y2 + ty;

  return dda(x1,y1,x2,y2);
}

Upvotes: 0

Views: 46

Answers (1)

NYG
NYG

Reputation: 1817

I suggest you always to put your JavaScript code in a document.onload event. It is always a good usage:

document.onload = function(){
   // your code
};

In jQuery you have a better choice:

$(document).ready(function() {
// your code
});

This way your code will always be executed when the document is fully loaded, so when all the js files are loaded.

Upvotes: 1

Related Questions