Pass an array and the index to update the variable.

Previous version of setSelectedId() doesn't update a variable:
currSelectedId, because it is a value not a reference.