How can I get a text field to populate based on conditions?