Fix JS error when adding new media

Use on and make it one liner.