tips tricks and useful things to do with javascript needed

craigp86

New Member
Messages
10
Reaction score
0
Points
0
I am new to javascript and i could do with some tips tricks and useful things i could us javascript for.any help is appreciated.
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
If you don't know what you need to use Javascript for then it is not particularly useful to use it just for the sake of using it.
Anyway, I'll go on regardless; Javascript has a multitude of uses from simple to complex:

• UI responses - Can be used to provide user feedback when actions such as clicks are placed on your page. The result could range from a simple alert() to more complex animations etc.

• Form validation - Used to ensure that data entered into a form by the client has the correct format; note that this should never be used as the final line of defence for validity as a user may have Javascript disabled, which would render your validation useless.

• AJAX - Used to provide a asynchronous link to the server for loading data, this could be used for search suggestions or a live chat-box, this avoids the need to reload the page to poll the server for data and greatly enhances the user's experience.

• Animation/DOM control - Timers and event listeners can be used to provide animation on your page. Javascript can also be used to create, edit and destroy elements on the page, this means you could alter the styles or content of your pages on the fly without having to reload the page. The simplest use of this may be creating a clock on your page or having rollover effects on certain elements.

• Maps - Google has a great map API that can be used to create a whole range of mapping sites and is both simple to pick up and very extensible to larger projects.

• Online apps - With the advent of web workers, webSockets, local storage and caching in modern browsers, it is now possible to connect and process at a greater rate than before, this makes it possible to create rich web applications that share many features with desktop counterparts.


I am just scratching the surface here for what Javascript can really do and the best way of finding its power is to look at pages that use it in a way you like and then you can look at the source and see how it was done. Javascript does obviously have its limitations though, and shouldn't really be used for heavy data processing, PHP or C are a lot better at tasks like that. Obviously, a few of these aren't really advisable for Javascript novices, but it is always best to learn a new programming language by working with it and writing it yourself.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
JavaScript is an incredibly powerful and expressive language; there's not a lot you can't do with it (especially in the HTML5 context -- the web workers, etc., that lemon-tree mentioned). It's my preferred language for server-side development as well (in the Rhino environment on the Java Virtual Machine, on the Jaxer server, in CouchDB) whenever it's available -- it does Lisp-y things using a syntax that doesn't play havoc with my emotional security.

That being said, one needs to be a little bit careful building a website that depends on JavaScript. If it's a web application, something that acts as a replacement for a desktop application or for a proprietary client/server application, you may be left with little choice. (Rich text editing, for instance, needs JavaScript in order to be WYSIWYG; without JS you are left with embedded codes like BBcode, Markdown, wiki markup or HTML, and need to wait for a round-trip to the server to see what you've done.)

If, on the other hand, you are running an information service or are involved in business-to-consumer activity (B2C), you need to create a site first that does everything it's supposed to do with JavaScript disabled. (Ideally, it should be completely usable with CSS disabled as well.) Once that is in place, you can "paint" enhanced behaviour onto the web page in order to provide additional features and make the user experience more pleasant. (I really have to write a progressive-enhancement tutorial at some point.)

Remember that if your site ever becomes successful, some portion of your user base (or at least of your potential user base) is either going to be disabled in some way (so usability and accessibility are key), are going to be behind corporate firewalls (and may have JS disabled by IT policy), are using "smart" phones that aren't so very bright at all, or will be ill-informed and paranoid (and will have JS turned off because they are afraid of what it might do). Those three groups can account for thirty percent or more of your potential users, depending on your target demographic. If you hope to make customers of these people (or even to gain ad revenue from them), you need to ensure that they can use your site even if it means a few extra clicks and a few extra trips to the server.
 
Top