Hi,
You would need to move the script to the layout:ready event. This isn't the most efficient event, because it fires every time the from changes. However because of this it suits your requirements well, because every time a row is added or deleted, the index numbers will update.
Here is a sample with letters (for a maximum of four rows). The same approach would apply to numbers. The script is in the layout:ready event of the first cell.
There is a sample here: https://acrobat.com/#d=Zk2XWWDUWNfG*VuRTNy5QQ
Good luck,
Niall