Q:

Setting onclick property for input

I need to set onclick property to the newly created element (input tag). It should be function with arguments. I use this: addButton.onclick = addToBasket(aHref[i].innerHTML, aHref[i].href);
But the problem is that this function calls automatically when window is loaded, but I need simply to set property. By the way if I use function without arguments like this: addButton.onclick = addToBasket; it works (isn't called automatically).

A:

Use instead:
addButton.onclick = function(){
    addToBasket(aHref[i].innerHTML, aHref[i].href);
}

onclick expects a function-definition. Another possibility is:
addButton.onclick = addToBasket;

But in this last one you will need to get the args from the function's inside, or with global variables.
It is because when you use () you are invoking the function-definition which will return some value or undefined.

