This is a discussion on "Why and what in javascript??" within the JavaScript Forum section. This forum, and the thread "Why and what in javascript?? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Why and what in javascript??
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Why and what in javascript??
Hi all.
I am pretty quick with xhtml and css, getting there on PHP but really don't have much of a clue in javascript. I guess it is an essential tool to have as it is the only way of server-side prgramming? But it is used in so many situations for bad things like annoying pop ups and sutff. hat is it actual uses? Is it worth my time learning it. What is AJAX? Is this more worth learning than JS? I think you get the drift of what I'm asking...let me know your thoughts. Mike |
|
|
|
#2
|
|||
|
|||
|
Re: Why and what in javascript??
It's an invaluable tool, Mike. It allows you the sort of control over page behaviour that you don't have otherwise. It is, as a rule for behaviour but has many different uses. Take suckerfish dropdowns, an almost perfect css solution but requires the aid of just a little JS to get it working. All you use in the case of the dropdowns is a simple show/hide function.
The important thing to bear in mind when thinking about using JS is that it can cause problems and has a bit of a poor reputation because of it's past in the form of DHTML. JS is there to add functionality. Look at lightbox, it makes viewing images more pleasant, more professional and a lot easier for the viewer. It is an ideal solution. However, if JS is switched off then a little of the functionality is gone but everything still works. AJAX basically allows you load things into a page (search results for example) without reloading the page. Again, this simply adds functionality, makes things quicker, less troublesome for the user. You could make it so that as something is typed into a search field results are automatically displayed underneath. The AJAX makes a request on every keystroke and displays the matches without reloading the page; it simply reloads a part of the page. Again it's important that if JS is switched off that the search feature works just like a traditional search feature. Another good use is when people are start rating products or favouriting articles. This can all be done without reloading the page, so the user experience is slicker. CSS can do a lot of the things that JS was traditionally used for. Rollovers, hover effects, even remote rollovers and CSS looks as though it will continue to provide clean accessible solutions. There are things that CSS can't do though. When you make a quick post, on these forums it doesn't reload the page, click on someones username, next to their avatar, and a little box opens up with even more options. JS and AJAX are exciting technologies (or methodologies) but with great power comes great responsibility. You can do a lot of damage with these tools, you could end up actually removing functionality. You see this all too often and it simply shouldn't happen. Graceful degradation, progressive enhancement. These are things that are spoken of occasionally (and not often enough in my opinion) but to many they mean very little. Progressive enhancement means that everything should work perfectly and you site should be totally accessible to all and then you should progressively enhance you sites functionality with small carefully considered bits of Javascript. Graceful Degradation is similar to this but the reverse, almost, your site should basically work perfectly well with JS switched off and should be thoroughly tested for this eventuality. Just like if you turn CSS of then you page should still display, well if JS is switched off then you site should still be viewable and all it's content accessible. No inline event handlers, in fact no inline JS at all, the DOM allows you to add all the functionality you could need by using the same sort of hooks that you use to apply CSS. Element names, classes and ids. So I think JS and AJAX is worth bothering as long as it is done correctly. It has a similar syntax to PHP so yo should get along quite well. I suggest you seek out anything that Jeremy Keith has said on the matter and buy his books DOM Scripting and Bulletproof AJAX. You won't go far wrong with them. You should also read this and this and this on the matter of accessible AJAX (or HIJAX). Did I go on, or what? Pete. |
|
#3
|
|||
|
|||
|
Re: Why and what in javascript??
Haha yea you went on but it was all useful knowledge so cheers!
Quote:
Cool i've bpookmarked all those links and will hunt down those books. Its annoying how people make stupid use of it cos when I type javascript learning resources it just comes up with all soprts of crap like flashing text and stuff like that. I don't want to know that - but I do want to learn how to use it effectively because up till now I have just knocked it off a cheap mans web scripting language. but now I see it actually has a lot of use and I really should have it available as a tool. While researching this question I found this quote: Quote:
Thanks for all the info. Mike |
|
#4
|
|||
|
|||
|
Re: Why and what in javascript??
Nice quote, as for the DOM it stands for Document Object Model. It is a way of accessing every element with a page. The mechanics of it are fairly complex but once you understand how it works it basically means that you can access and modify and element on a page on-the-fly. So the DOM is another standard that most modern browser support, unlike in years gone by where you would have to do lots of browser sniffing and supply different JS to different browser there is relatively good support for the DOM. As a rule I test for support of a DOM method before I use it rather than running convoluted browser checking code. If the method isn't supported then it simply falls back to the perfectly functional non-JS version.
The DOM practically speaking can be used in many ways. Four very useful DOM methods are getElementById, getElementsByTagName, getAttribute and setAttribute. These elements work exactly as they appear to, it's quite simple and a very efficient way to select a specific part of a page or element.
Similar to this is:
These two are also very handy:
Another handy DOM method is this one:
As you can see, using the DOM you can do all manner of things but not only that you can do them without sprinkling inline javascript all over your pages as you can access the full contents of your page via external .js files and just link them as you do css. I'm no expert and this is very basic stuff but it is one of the reasons why the use of both javascript and the DOM should be pushed big time; you can increase usability without compromising accessibility. Pete. Last edited by pa007; Aug 22nd, 2007 at 22:06. |
|
#5
|
|||
|
|||
|
Re: Why and what in javascript??
Another point is that a lot of stuff that can be done with CSS really shouldn't. I love CSS Play but what Stu Nicholls is doing is pushing the boundaries of what can be done, he's not saying that you should do it that way. I love his image galleries but I would much rather layout the image gallery with css and then add things like hover effects, remote rollover effects and show/hide effects afterwards using JS. Some people will disagree but I prefer to do my presentational stuff with CSS and leave the behavioural features to JS. One big exception is text/nav rollovers. CSS support is so good and the solutions available so accessible that it makes sense to use CSS but other things seem over complex for me and are basically hacks as CSS was never meant for that sort of thing.
Pete. |
|
#6
|
||||
|
||||
|
Re: Why and what in javascript??
I want to learn JS. But I look at the code and syntax and I just can't be bothered.
But I'm going to force myself to learn Do you reckon I should start at w3schools? I like their tutorials but are they any better ones? Thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Tags |
| javascript, needed |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| php and javascript | yvettesio | JavaScript Forum | 8 | Mar 14th, 2007 23:18 |
| JavaScript | cbrams9 | JavaScript Forum | 1 | Sep 20th, 2006 17:35 |
| using xml in javascript | shailu | JavaScript Forum | 0 | Jul 25th, 2006 07:36 |
| Can someone help me with this javascript | Galaxyblue | JavaScript Forum | 2 | Mar 11th, 2004 12:18 |
| what does \\ mean in javascript | jenjen1018 | JavaScript Forum | 5 | Jan 6th, 2004 17:05 |