So the way you've done things is you've basically got two "link" handlers that both overwrite the same default handler and don't actually check what the link span is, so it's defaulting to the second alert since that's the most recent one that got put in. That's why it's not working, you instead want to check which span is clicked.
What you want is something like this:
on link x do if x~"link1" alert["ah!"] end if x~"link2" alert["ee!"] end end
So like, the logic is you have one link handler and then within that you check which one was clicked and do whatever accordingly.
I've put this in just the script for the field, that way you can have different ones in other fields.