views:

99

answers:

6

I have been developing websites for some time now and I hardly use any Javascript in my pages.

Whatever I can want to do with JavaScript, it is possible through PHP. Just like ajax itself. We can send a regular request instead of a ajax request, can't we? We can use "include" to include sub part of pages.

So am i missing something about javascript, that I dont know of?

A: 

JS allows you to respond to users interacting with a page (such as moving the pointer over an element) and to perform operations without a (relatively) expensive round trip to the server.

David Dorward
+4  A: 

The point of Javascript is that it is a client side technology. It allows you to do stuff on the browser instead of the server.

Simple example - you want to let the user enter some numbers and then you perform some calculation on these and display the results.

With Javascript, this would all happen on the browser, the server will not be involved.

If however, you didn't use Javascript, the data would need to be posted to the server and you will need to calculate and display with the server, using server resources.

Javascript allows you to move expensive operations to the client.

Oded
Oh yeah, and it's clientside - not server side ;)
Neurofluxation
+4  A: 

The comprehensive jQuery library will allow you to animate smoothly with various different effects (sometimes with better results than flash).

AJAX also allows for no-page refreshes, pages can be updated on-the-fly.

jQuery: http://www.jquery.com/ User Interface demos: http://jqueryui.com/demos/

With response to that comment below from @silky:

There are many more circumstances where using JavaScript is the only option. How about events? JavaScript is the only language available for having your website communicate with the browser and watch for events: clicks, double clicks, mouse enters, mouse exits, key presses, browser window sizing... the list goes on. If you need access to those events, you are in JavaScript territory.

Taken from: http://css-tricks.com/you-know-you-should-use-javascript-when/

Neurofluxation
This post has the magic instant-upvote "jQuery" term in it, but it doesn't actually explain why JavaScript should be used ...
Noon Silk
A: 

If you want your website to be more user friendly and easy to use you will need javascript.

Would you wait till this website (Stackoverflow.com) refresh your page, to see your comment updated?

Starx
no i wouldn't wait
+1  A: 

Take for instance Stack Overflow. If someone posts an answer while you are writing one, a popup will come out saying "there is a new answer". Note that the page is not reloaded in this process.

That would not be possible by only using PHP: although it does make use of a server-side language to query for new answers, this is called in background using Javascript (this is an example of AJAX).


Also, with PHP you cannot catch user interaction with the site, as once the PHP page is loaded the server doesn't know anything about what is going on in the client.

nico
A: 

Its the language for programming the web agnostic of any platform Windows, Linux etc. It can be used to do both client and server side development.

nitroxn