Javascript or PHP ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajit09
    Contributor
    • Dec 2006
    • 296

    Javascript or PHP ?

    Hello,

    In web development should we do more processing on client side (javascript) or server side (PHP) ?
  • Tarantulus
    New Member
    • May 2007
    • 114

    #2
    that entirely depends on what you aim to do.

    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

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      Originally posted by pankajit09
      Hello,

      In web development should we do more processing on client side (javascript) or server side (PHP) ?
      That depends upon what processing it is.

      If your page has to find product of two numbers, then do that in JavaScript. PHP would give slow response in that case.

      If your page adds or fetches some data to the database, use PHP. JavaScript alone won't do anything.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by pankajit09
        Hello,

        In web development should we do more processing on client side (javascript) or server side (PHP) ?
        Using just one or the other isn't possible.

        Use must learn to utilise both these languages.

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          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).

          Comment

          • pankajit09
            Contributor
            • Dec 2006
            • 296

            #6
            In case of Ajax what should be the choice ?

            Comment

            • coolsti
              Contributor
              • Mar 2008
              • 310

              #7
              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.

              Comment

              • pankajit09
                Contributor
                • Dec 2006
                • 296

                #8
                Originally posted by coolsti
                ...........
                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.
                Thats fine but I still didn't get the answer.

                Comment

                • perhapscwk
                  New Member
                  • Sep 2007
                  • 123

                  #9
                  Originally posted by pankajit09
                  Thats fine but I still didn't get the answer.
                  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.

                  Comment

                  • vijay
                    New Member
                    • Aug 2006
                    • 31

                    #10
                    Originally posted by pankajit09
                    Hello,

                    In web development should we do more processing on client side (javascript) or server side (PHP) ?
                    It depends on the framework u use

                    if u use struts the validation can be done mostly on server side
                    by using the struts validaion

                    So if we have nay validation techniques its beter to use the serverside

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Ajax is JS and PHP combined.

                      Comment

                      • coolsti
                        Contributor
                        • Mar 2008
                        • 310

                        #12
                        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.

                        Comment

                        • BigDaddyLH
                          Recognized Expert Top Contributor
                          • Dec 2007
                          • 1216

                          #13
                          Originally posted by markusn00b
                          Ajax is JS and PHP combined.
                          The AJAX (=asynchronous JavaScript and XML) technique is server-side agnostic. It could just as well be running Java on the server.

                          Comment

                          • BigDaddyLH
                            Recognized Expert Top Contributor
                            • Dec 2007
                            • 1216

                            #14
                            Originally posted by coolsti
                            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).

                            Comment

                            • Atli
                              Recognized Expert Expert
                              • Nov 2006
                              • 5062

                              #15
                              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

                              Working...