OnPanelSwitch is a "before the event" trigger. It performs its designated script, then the event that tripped the trigger, selecting the slide 4 panel, is processed and thus the focus is lost.
You can keep "before" triggers from being messed up by the triggering event if you end your script with:
Exit Script [False]
For a list of all script triggers in a table which shows which are "before" and which are "after" the triggering event, see "setting up script triggers" in FileMaker Help.