Client side authentication, as far as I concern, requires you to include the username and password inside the file itself. So, user will be able to see it.
This is obviously not reliable if you wanna implement higher security.
I would highly recommend u to use cookies or session for this. .htaccess is also another alternative. 🙂
If you insist to use Javascript, please visit javascript forum for details coz I believe that we handle PHP better than javascript here. Good luck!