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);
}
Cœur
39k25 gold badges207 silver badges282 bronze badges
asked Oct 8, 2017 at 18:18
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.

answered Oct 8, 2017 at 18:28
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.