small switch function for from and to fields