That doesn't work exactly how I want it. But I've managed to make it in JavaScript now anyways. It's not quite a neat, but it works.
Thanks anyway.

edit: I'd never known about that action, thanks for pointing it out to me.