Html:
<input type="button" onclick="javascript:SetIndex(this)" value="one" />
<input type="button" onclick="javascript:SetIndex(this)" value="two" />
<input type="button" onclick="javascript:SetIndex(this)" value="three" />
<input type="button" onclick="javascript:SetIndex(this)" value="four" />
JavaScript:
var array = [0,1,2,4];
var index = 0;
function SetIndex(obj)
{
// check if index is out of range and it might be useful
// to see if this button already has an index assigned
if (index < array.length && isNaN(obj.index))
{
obj.title = array[index]; // hover to see index...
obj.index = array[index];
index++;
}
}
working example: http://jsfiddle.net/hunter/eS4qy/