after all you wouldn't use a screwdriver to bang in a nail, when you have a hammer in arms reach!
what I mean is, PHP and javascript are quite different beasts, as a rule of thumb, aesthetic code (DHTML etc) is handled by JS everything else is PHP IMHO
Last edited by Tarantulus; May 29 '08, 03:01 PM.
Reason: Clarification
A PHP programmer will have mostly server side, with some client side. A javascript programmer will do the opposite. You ultimately will need to know both, but almost certainly more of one than the other. Most of us here use PHP more, but other people will use Javascript more. My advice, choose one and jump into it and you will see if you like it. Regardless of if you do, learn a bit of the other so you know what the alternative is. But start with one (your choice).
I started out learning PHP and making my application basically without Javascript, but as I learned Javascript more and more, and found I needed more and more client side dynamics, I have incorporated it more and more. Now Javascript is an essential part of my work.
I am the only one working on my application projects, which is a very exciting adventure, because I do both the front and back end programming. Coordinations (like setting up meetings with myself) is a piece of cake, and the programmer on both front and back ends (me) knows exactly what the other wants ;) But because of this I have had the pleasure of learning both PHP and Javascript (and much more).
But I have not yet taken the plunge to using Ajax. I am using what I suppose came before Ajax was developed, by putting a hidden iframe in the page and using Javascript in the main page and iframe to do whatever background work I need without refreshing the main page, and changing elements in the main page dynamically as needed. I believe Ajax lets you do this a bit more elegantly, but my way works for me.
...........
But I have not yet taken the plunge to using Ajax. I am using what I suppose came before Ajax was developed, by putting a hidden iframe in the page and using Javascript in the main page and iframe to do whatever background work I need without refreshing the main page, and changing elements in the main page dynamically as needed. I believe Ajax lets you do this a bit more elegantly, but my way works for me.
What i think is of course client side javascript is faster, so if the case that
we can use client side javascript, then use it, always client side javascript first
so it can make your site run faster.
I guess I didn't give you really an answer to your question. To use PHP or Javascript depends on what you are needing to do with/on the particular page.
I use Javascript when I want some decision to be performed on the client side without needing to first contact the server where the PHP is running. This could be to do many tasks, here are some examples:
1) Determine which button that the user pressed, telling the server PHP scripts what to do next (I do not use multiple forms on my pages, just one form and I use Javascript to tell the server where to go next).
2) Submit an iframe to perform a background query without doing a complete new page request (Ajax stuff). This may be because I just wish to update some fields based on user selection, or to avoid rebuilding a page which is time consuming to produce or download.
3) Open up auxiliary windows to show stuff (popup windows).
4) Provide dynamics on the page according to user interactions.
All of the above cannot be done on the server side, at least not efficiently, and so are done on the client side using Javascript.
For user input validations, I do this sometimes on the client side with Javascript, but mostly on the server side after the page was submitted using PHP.
For user input validations, I do this sometimes on the client side with Javascript, but mostly on the server side after the page was submitted using PHP.
Unless you completely trust your clients (hi, grandma!) you must validate input on the server-side even if you're already doing client-side validation (for good validation response).
I tend to avoid Javascript as much as I can. Mostly because Javascript is run on the clients browser, and can therefore be turned of or mutilated in other ways.
With PHP I know it will never be bypassed or executed incorrectly by the browser. It is simply more reliable that way.
Comparing AJAX and PHP is completely useless. They are nothing alike... It's like comparing a car to a spaceship... just doesn't make sense.
Comment