come hai ben detto si fa in JS, non in PHP, al limite puoi stampare il codice JS con PHP ...