you can, but not without refreshing the page first. php is server side, meaning it runs on the webserver, before any html reaches the users browser. javascript is client side and runs in the users browser once the page has loaded and php has gone away. javascript is really the only good way to do it.