I have read in other answers that in order to use a function as a parameter, it needs to be written whatever;and not whatever()because this las option “calls” the function. But what if I need to specify a parameter of said function? I give an example:
I have this function to replace some content:
function navigate(content) {
var card = document.getElementById('informationdiv');
card.innerHTML = content;
}
And then I have another function that creates the content:
function productsheet(article) {
document.write(array_products[article].Name);
document.write(array_products[article].Number);
document.write(array_products[article].Type);
// and so on...
Then, I want to call the first function like this:
navigate(productsheet(article));
And instead of do the innerHTML replacement, it just runs productsheet(article)overriding everything else.
As I said, I found similar problems where the solution was to pass productsheetwithout (article), but in my case I need the article parameter, so productsheetknows what to print…
What is the suggested approach here?
Thank you very much!
There are much better ways to achieve what you want, but taking your code as starting point I would do as follows:
Again, I think you should rethink the whole approach and throw this code away.