Samuel
Former Coding Moderator
:D
Posts: 154
|
Post by Samuel on Nov 3, 2006 17:29:21 GMT -5
Well this is gonna be my diary for JavaScript(I will prbably refer to it as JS). Everything I do with JS I will sum up into a Diary entry, and post it in this thread. And remember, a little Boy can't remember everything that he's learned.
|
|
Samuel
Former Coding Moderator
:D
Posts: 154
|
Post by Samuel on Nov 3, 2006 17:51:34 GMT -5
Well, I might as well start with the basics, I didn't revise this, but I'm going to for you guys. So firstly, I popped over to HTMLgoodies and had a look at the first Javascript tutorial. I'm gonna skip all the stuff about Javascript. But if you wanna read it, read this short paragraph(s): Quoted from HTML Goodies: JavaScript is an scripting language that is primarily used for creating interactive features on webpages. It can be used to create menus, validate forms, swap images, or just about anything else you can think of to do on a webpage. If you have ever taken a look at Google Maps or Google's GMail service, you have an idea of what JavaScript is capable of today.
Since JavaScript is currently the only scripting language supported by every major web browser (Internet Explorer, Firefox, Netscape, Safari, Opera, Camino, etc), it is very widely used. When code is rendered by your web browser, like JavaScript usually is, it is called a Client-Side script. JavaScript can also be run on a web server to generate HTML documents, thus running as a Server-Side script. Although its use is usually limited to client-side scripts, JavaScript can be a very powerful server language as well.
If you are going to be writing JavaScript code, all you really need is a text editor and a web browser. Knowledge of HTML and CSS will definitely help, and if you want to use your JavaScript skills on a website, you are going to also need your own website. If you already have your own website, great! If not, there are plenty of free servers available that you can choose from to host your pages.
As for a text-editor, if you are using Windows than you should already have NotePad installed. Although this will work for editing JavaScript, HTML and CSS, a more robust editor would be a good idea. My personal favorite is EditPlus, which has a free trial period of 30 days, but you can use it indefinitely if you are willing to put up with its nag screen. If you like EditPlus however, and you continue to use it, you should register it.
Now that you know what JavaScript is, let's get started with your first script!
First, we need to know how to add JavaScript to an HTML page. JavaScript can be added in one of two ways: You can place Script tags in your webpage and place the JavaScript code inside of those. Or you can place all of your JavaScript code in another file and link to it with a Script tag. Either of these methods is perfectly valid, but they have different purposes. If you just have a short piece of code that is only going to be used on one page, placing that code in script tags is a good way to go. If, however, you have a large piece of code that you are going to be using on several pages, you will probably want to place that JavaScript code into a separate file and link to it. This is done so that people do not have to download all of your code every time they visit a different page. They download it once and then their browser saves it for future use. If you are familiar with CSS (StyleSheets), they pretty much work the same way. I hope you enjoyed that. I'm going to write my own Tutorial, looking at what Mark Kahn(the Writer) put in his tutorial(I'll be adding a lot more though).
To start EVERY JS script we need at least a <script> and a </script> tag, but correctly we need to use: <script type="text/javascript"> <!--
// Code would go here
// --> </script>
Now I suppose I have to explain everything in this teeny weeny script. <script type="text/javascript"> the <script bit starts the script, then the type="text/javascript" tells the browser that it's a javascript file. <!-- this is for older browsers, if it doesn't understand the script, it won't print the script onto the page. //Code would go here The // part start a comment, there are also a multi-line comment /* Anything between these is a comment */. Comments are ignored by the browser. The text is just to tell you that a code would go there. // --> This bit ends the older browser bit, I hae no idea why it has to be commented, but just go with the flow and you'll be ok. </script> Clearly ends the scripts.
Something to put in the script place is an alert box. commonly used to tell the user something(like a password is wrong). <script type="text/javascript"> <!--
alert("hi");
// --> </script> alert("hi"); This brings up an alert saying Hi That's all for tonight, I'm pretty tired and I have something important to do over the weekend.
|
|
Samuel
Former Coding Moderator
:D
Posts: 154
|
Post by Samuel on Nov 28, 2006 12:14:18 GMT -5
I'm not very consistent am I? Well I plan to have at least 2(ZOMG 2!) Entries added to this, I'll also be deleteing this post.. so read it whilst you can!
Strike up the band! WoOw ho! the conductor is beckoning Come congregation,let's sing it like you mean it. No. Don't you get it don't you get it? Now don't you move...
|
|
Simie
Coding Admin
Why are you all still here?
Posts: 721
|
Post by Simie on Nov 28, 2006 13:42:44 GMT -5
I think you should delete it now (Feel free to delete this one aswel )
|
|
Samuel
Former Coding Moderator
:D
Posts: 154
|
Post by Samuel on Nov 29, 2006 10:43:08 GMT -5
why?
|
|
Simie
Coding Admin
Why are you all still here?
Posts: 721
|
Post by Simie on Nov 29, 2006 11:18:40 GMT -5
No idea. (*stops spamming up thread*)
|
|
Samuel
Former Coding Moderator
:D
Posts: 154
|
Post by Samuel on Dec 2, 2006 8:50:51 GMT -5
Now I'm going to tell you about some basic JS functions, like alert. Well oviously, alert is one, which displays text. this is done like so: alert("My text");That would bring up a alert boxPretty simple. Now I'll give you a new one - document.write() , this' format is the same as alert() but it writes text onto a document. e.g: document.write("I wrote this text with javascript!"); Heres an example: exampleNow you know how to do those, you mgiht as well learn about variables. variables are the thing you'll use ALL the time, so I suggest you pay attention. What is that you ask? Yes, it is in fact the thing that starts with var, like this var myVariable = "A String";It can also store numbers - var myNumber = 5; or a JS function - my jsFunction = alert("HI!");You can use varibles to stop repeating yourself, say you wanted a lert and something wrote on the page. <script type="text/javascript"> <!--
var myText = "Hello, my name is Sam"; alert(myText); document.write(myText);
// --> </script>That would do just that. Also, don't forget that variables are CASE SENSITIVE! CASE SENSITIVE! CASE SENSITIVE!. Sorry for me repeating myself but it seems to help if i say it 3 times. That's all for now, I'll probably add some more to this post later on today.
|
|