refactor form element selection into helper function