sale being the name and count5 being the variable containg numbers.
i need to combine the sale with the variable and change the onclick to that.
any ideas
what i need to do is change what the onclick event does.
i need it to change a div onclick from sale1() to whatever is in the variable.
ranging from sale1 to sale33.
<div id = "myid">Something here</div>
<script type = "text/javascript">
var count5 = 1; // a number determined by ?
var sale = {
sale1: function() {alert ("function sale1 activated") },
sale2: function() {alert ("function sale2 activated") },
sale33: function() {alert ("function sale33 activated") }
};
document.getElementById("myid").onclick = function(){
sale['sale' + count5]();
};
</script>
You will see that the functions are stored in an object. You could also access the functions directly from the window object but this has the disadvantage of using the global namespace, which many consider should be avoided.
Following protracted negotiations we have come to an arrangement with the banks under which we have agreed not to supply goods to our customers on credit. For their part the banks have agreed not to sell fishing tackle.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 06-27-2012 at 09:18 PM..
Reason: Noticed typo