Javascript or PHP? You need both. Javascript is browser-side scripting why PHP is server-side scripting. You need a combination of the two to elegantly accomplish what you want.