0

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);
}
2
  • You haven't mentioned a problem. There is nothing stopping you from calling a function defined in another file beyond making sure the file that has the function is loaded first. Also in your example you don't do anything with the returned value you in your click handler Commented Oct 8, 2017 at 18:28
  • what i want to know is how can i use the value that i returned and execute the function dda, all that executing only the function tranlation. Commented Oct 8, 2017 at 19:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.