I have following code (html,js,jquery) snippet (http://jsfiddle.net/MUScJ/2/):
<script type="text/javascript">
function someFunc(){
html = '';
z = 1;
for(i=0; i<5; i++){
html += '<input type="button" value="Button_'+z+'"' +
'onclick="otherFunc(z);">';
z++;
}
$("#container").html(html);
return true;
}
function otherFunc(z){
alert('z:' + z);
return true;
}
</script>
<div id="container"></div>
<input type="button" value="Go" onclick="someFunc();" />
This script outputs five buttons with onclick event. JS function otherFunc always returns z variable equal to 6. Is it possible to overcome this ? I want every button have its specific z value - 1,2,3.. and etc.
Any ideas ?