I see a flaw in the logic when you reset a to the truncated me.gisname.value. You don't want to reset the a value. I'm assuming that you want each repeated value to be truncated more than the previous. So if you have, let's say the string HELEN three times, you want to get HELEN, HEL, H. Try...