Logic error in jquery for loop on create event page.