Bentley4 Posted May 18, 2011 Share Posted May 18, 2011 Hi everyone, I understand that Js is clientside and php is serverside. But why would anyone want to do clientside programming when you can do serverside programming? Could you give some examples from sites and say what is better to do in javascript and what is better to do in php? Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/ Share on other sites More sharing options...
KevinM1 Posted May 18, 2011 Share Posted May 18, 2011 Hi everyone, I understand that Js is clientside and php is serverside. But why would anyone want to do clientside programming when you can do serverside programming? Could you give some examples from sites and say what is better to do in javascript and what is better to do in php? It's not that one can do something better than the other, it's that each offers different capabilities, and each is used for different purposes. PHP is a back end processing language. As such, it's responsible for handling data requests (saving/retrieving data from a database) and showing the results of those requests. JavaScript is a language primarily used to manipulate the Document Object Model (DOM) of an HTML page. It's essentially used as a user interface scripting language, which allows sites to be more interactive. The two languages are used together with AJAX, which allows you to send a request to your PHP script through JavaScript, and then process the return data with JavaScript, removing page refreshes from the process. That is how apps like Google Maps work. Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1217003 Share on other sites More sharing options...
Bentley4 Posted May 18, 2011 Author Share Posted May 18, 2011 But php is interactive as well, no? Is there anything in js that you couldn't actually write in php? Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1217017 Share on other sites More sharing options...
gristoi Posted May 18, 2011 Share Posted May 18, 2011 Drag and drop, sortable lists on the fly without page reloading......................... the list goes on Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1217029 Share on other sites More sharing options...
KevinM1 Posted May 18, 2011 Share Posted May 18, 2011 But php is interactive as well, no? Is there anything in js that you couldn't actually write in php? PHP is not interactive. It has no concept of events, and cannot react to a user doing something to the rendered output. All PHP does is respond to HTTP requests - GET or POST - and that requires a page load, either a refresh or a new load based on the user being redirected to another page. Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1217031 Share on other sites More sharing options...
JonnoTheDev Posted May 18, 2011 Share Posted May 18, 2011 The answer to your original post cannot be put any better than Nightslyr's response Is there anything in js that you couldn't actually write in php? As you have stated yourself, JS is a client side language i.e it is executed by your web browser. PHP isn't, therefore 90% of the examples on the following page cannot be done with PHP: http://www.noupe.com/jquery/50-amazing-jquery-examples-part1.html Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1217050 Share on other sites More sharing options...
ignace Posted May 18, 2011 Share Posted May 18, 2011 JS and PHP both serve a different need. JS is aimed at rich-media interaction while PHP is aimed at data processing and enforcing business rules. You can't enforce these constraints at the client's computer. That said though doesn't mean JS can't interact with a database, it sure can but it wouldn't be secure for the same reason you use session's instead of cookies. Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1217194 Share on other sites More sharing options...
Bentley4 Posted May 21, 2011 Author Share Posted May 21, 2011 K, thnx guys Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218381 Share on other sites More sharing options...
dreamwest Posted May 22, 2011 Share Posted May 22, 2011 Javascript is very similar to php so why not learn it. I use javascript like crazy in my tax tracker program i built, i can do my tax in 1 hour when before it took 2 weeks Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218603 Share on other sites More sharing options...
trq Posted May 22, 2011 Share Posted May 22, 2011 Javascript is very similar to php so why not learn it. JavaScript is nothing like PHP. Syntax wise, maybe a little, but that is about where the similarities end. It has a completely different inheritance model based on prototypes. Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218604 Share on other sites More sharing options...
dreamwest Posted May 22, 2011 Share Posted May 22, 2011 Javascript is very similar to php so why not learn it. JavaScript is nothing like PHP. Syntax wise, maybe a little, but that is about where the similarities end. It has a completely different inheritance model based on prototypes. Yes darling similar - not identical Javascript function test(txt){ if(txt){ alert("Txt is valid"); }else{ alert("no txt"); } }//end test Php function test($txt){ if($txt){ echo "Txt is valid"; }else{ echo "no txt"; } }//end test Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218605 Share on other sites More sharing options...
trq Posted May 22, 2011 Share Posted May 22, 2011 Yes darling similar - not identical Do not patronize me, smart ass. I'm sure your know very little about what I am even referring to. Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218614 Share on other sites More sharing options...
dreamwest Posted May 22, 2011 Share Posted May 22, 2011 Yes darling similar - not identical Do not patronize me, smart ass. I'm sure your know very little about what I am even referring to. Thats the way i talk i call everyone darling Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218616 Share on other sites More sharing options...
trq Posted May 22, 2011 Share Posted May 22, 2011 And I am sure that works brilliantly for you. Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218618 Share on other sites More sharing options...
dreamwest Posted May 22, 2011 Share Posted May 22, 2011 And I am sure that works brilliantly for you. It made you love me more Quote Link to comment https://forums.phpfreaks.com/topic/236744-why-should-you-learn-javascript-when-you-know-php/#findComment-1218620 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.