You can use AJAX with PHP, by AJAX make the php validation without
refreshing the page, after submitting do the validation again for
security. This is more friendly for users, and you can use php power
all the time.. (JS have a lot of bugs, use PHP cause of that)..
You can find a 5 minute tutorial at :
http://www.nurazije.co.nr/2006/10/5-minutes-ajax-tutorial.html