Post by g0alieb0y on Jul 19, 2005 7:20:54 GMT -5
Made By g0alieb0y from gb0y XC. Do not remove link.
gb0yxc.proboards41.com/index.cgi
Welcome to my Javascript guide! First lets get some rules down:
1 - You may repost this guide
2 - You may not edit this guide
^ Note that if any rule is broken you will have the chance of you forum being deleted ^
--------------------------------------------------------------------------------------
Calling the Script
--------------------------------------------------------------------------------------
Ok, first to start your script you will need to write <script> to call your script. So to end your script you would write </script>. So far you should have something like this:
<script>
<!--
-->
</script>
Well i know what your thinking. Your wondering why i added <!-- -->. Right? Well this is nothing major. It will just hide the script from old browsers that don't support JS (Javascript).
--------------------------------------------------------------------------------------
Adding Comments
--------------------------------------------------------------------------------------
Now lets get started with comments! There are two different types of comments that you can use in JS:
// A Single line Comment
/* A Multiple line
Comment */
Ok now that you see what a comment looks like you are probably wondering what it does. Well a comment doesn't really do anything. That's whats so great about it! You can use comments like instructions or you can use them to copyright your code! Lets take a look at this script:
<script>
<!--
/* This script does nothing */
-->
</script>
Now lets break this script down to each line. Ok on the first line you can see that we are calling the script. On the second line we are hiding the script from old browsers. On the third line we are making a multiple line comment that says that This script does nothing. Then on the same line we are ending the comment. On the forth line we end hiding the script. On the last line we end the script.
--------------------------------------------------------------------------------------
Writing to the Document
--------------------------------------------------------------------------------------
Well what does Writing to the Document mean?
When you write to the document you are basically just writing to the page. So this is the simple code that you would want to add to write to the page through JS:
document.write("Whats up?");
This code will write "Whats up?" to the page. Remember that you can not use "quotes" inside of a document.write tag.
There are many more ways to use a document.write tag but we will get to those in our variables section.
--------------------------------------------------------------------------------------
Variables
--------------------------------------------------------------------------------------
Variables are just ways to support data that you can use multiple times in many different ways. First well show you a code then look at all of the lines in it to see what it does:
<script>
var WhatsUp="Whats up?";
document.write(WhatsUp);
</script>
Ok, on line one we are calling the script. Now on line two we are making a variable named WhatsUp. WhatsUp's content is "Whats Up?". Then on line three we are writing the variable WhatsUp. Note that when we are writing the document.write line we are not using "quotes". If we did, it would write WhatsUp. So on the last line we are ending the script. This code will write "Whats Up?" on the screen.
So to make a variable you just need to add this code:
var Test="Anything here";
Remember that you can always make more than one variable and that you can always use them more than once.
--------------------------------------------------------------------------------------
Arrays
--------------------------------------------------------------------------------------
Arrays are like variables but they save room. Here is the line that you would have to add to make an array:
var Array1=newArray("Wow","This","Is","Cool");
You can always change Array1 to anything you want. Also you can edit what's inside of the quotes and add more quotes.
So know we will make a code then go through it:
<script>
var Array1=newArray("Wow","This","Is","Cool");
document.write(Array1[0]);
</script>
On the first line we call the script again. On the second line we make the array named Array1. On the next line we write a part of the array. It will write the content in the first quotes. I know, it's weird how it doesn't start from one but thats how it works. So now the page will have Wow written on it. And once again we end the script on the last line.
--------------------------------------------------------------------------------------
Alerts
--------------------------------------------------------------------------------------
An alert is a little popup that opens when you visit a page. You can change what is in the popup easily. Hers the alert code:
var Alert1="This is the alert content. (only on one line)";
alert(Alert1);
Now lets take a look at this code. On the first line me make a variable with the content of the alert. Then on the second line we use a code so the alert opens with the content of var Alert1.
Pretty easy, huh?
--------------------------------------------------------------------------------------
Prompts
--------------------------------------------------------------------------------------
Well prompts are just like alerts but you can do more stuff with them. A prompt has a textbox in it so you can ask a question and then the other person can write the answer in the textbox. Lets take a look at this code:
<script>
<!--
var Prompt1="What is your favorite color?","";
prompt(Prompt1);
-->
</script>
On the first line we are calling the script again. Next we hide the script from old browsers. Then on the third line we make a variable named Prompt1. Notice that you will have the text in the first pair of quotes and the text in the texbox in the second pair of quotes. Then on the forth line we write the prompt on the page. Anyways, on the next line we end hiding the script, and then to finish the job we end the script.
Here's another way to make a prompt:
prompt("Whats Up?","")
This way is good for small prompts and will save you room.
--------------------------------------------------------------------------------------
Simple If-Then Statements
--------------------------------------------------------------------------------------
Ok, we won't get into if-then statements because you can do so many stuff with if-then statements. So lets take a look at this code:
<script>
var question=prompt("Whats the password?","Hint: gb0y");
var answer="g0alieb0y";
if(question==answer){
alert("Correct!");
}else{
alert("Nope. Your wrong.");
}
</script>
On the first line we call the script. Next on the second line we make a prompt and the variable. On the third line we made a variable which was the password to get through. So on the forth line we start the if. It says if question (the content put in the second quote by a person) == answer (the variable answer) {. The { symbol starts what will be in the if. Anyways, on the next line we make an alert if you enter the right password writing "Correct!". On the sixth line we end the if with the } symbol then write else which will do something else if you don't do whatever is in the if. So we start the else with the {. Then on the seventh line we make an alert writing "Nope. Your wrong." if you don't enter the correct password. Then we close the script on the last line.
Wow that was alot of text.
Now we will do part of an if-then statement so if the URL is the right URL it will do something.
if (location.href.indexOf('URL')!= -1){
var anything="Pretty simple, right?";
document.write(anything);
}
^ This code is great for proboards! ^
--------------------------------------------------------------------------------------
Thank You!
--------------------------------------------------------------------------------------
Thank you for visiting my first Javascript tutorial! You may repost it but please read the rules at the top before you do
~gb0y
gb0yxc.proboards41.com/index.cgi
Welcome to my Javascript guide! First lets get some rules down:
1 - You may repost this guide
2 - You may not edit this guide
^ Note that if any rule is broken you will have the chance of you forum being deleted ^
--------------------------------------------------------------------------------------
Calling the Script
--------------------------------------------------------------------------------------
Ok, first to start your script you will need to write <script> to call your script. So to end your script you would write </script>. So far you should have something like this:
<script>
<!--
-->
</script>
Well i know what your thinking. Your wondering why i added <!-- -->. Right? Well this is nothing major. It will just hide the script from old browsers that don't support JS (Javascript).
--------------------------------------------------------------------------------------
Adding Comments
--------------------------------------------------------------------------------------
Now lets get started with comments! There are two different types of comments that you can use in JS:
// A Single line Comment
/* A Multiple line
Comment */
Ok now that you see what a comment looks like you are probably wondering what it does. Well a comment doesn't really do anything. That's whats so great about it! You can use comments like instructions or you can use them to copyright your code! Lets take a look at this script:
<script>
<!--
/* This script does nothing */
-->
</script>
Now lets break this script down to each line. Ok on the first line you can see that we are calling the script. On the second line we are hiding the script from old browsers. On the third line we are making a multiple line comment that says that This script does nothing. Then on the same line we are ending the comment. On the forth line we end hiding the script. On the last line we end the script.
--------------------------------------------------------------------------------------
Writing to the Document
--------------------------------------------------------------------------------------
Well what does Writing to the Document mean?
When you write to the document you are basically just writing to the page. So this is the simple code that you would want to add to write to the page through JS:
document.write("Whats up?");
This code will write "Whats up?" to the page. Remember that you can not use "quotes" inside of a document.write tag.
There are many more ways to use a document.write tag but we will get to those in our variables section.
--------------------------------------------------------------------------------------
Variables
--------------------------------------------------------------------------------------
Variables are just ways to support data that you can use multiple times in many different ways. First well show you a code then look at all of the lines in it to see what it does:
<script>
var WhatsUp="Whats up?";
document.write(WhatsUp);
</script>
Ok, on line one we are calling the script. Now on line two we are making a variable named WhatsUp. WhatsUp's content is "Whats Up?". Then on line three we are writing the variable WhatsUp. Note that when we are writing the document.write line we are not using "quotes". If we did, it would write WhatsUp. So on the last line we are ending the script. This code will write "Whats Up?" on the screen.
So to make a variable you just need to add this code:
var Test="Anything here";
Remember that you can always make more than one variable and that you can always use them more than once.
--------------------------------------------------------------------------------------
Arrays
--------------------------------------------------------------------------------------
Arrays are like variables but they save room. Here is the line that you would have to add to make an array:
var Array1=newArray("Wow","This","Is","Cool");
You can always change Array1 to anything you want. Also you can edit what's inside of the quotes and add more quotes.
So know we will make a code then go through it:
<script>
var Array1=newArray("Wow","This","Is","Cool");
document.write(Array1[0]);
</script>
On the first line we call the script again. On the second line we make the array named Array1. On the next line we write a part of the array. It will write the content in the first quotes. I know, it's weird how it doesn't start from one but thats how it works. So now the page will have Wow written on it. And once again we end the script on the last line.
--------------------------------------------------------------------------------------
Alerts
--------------------------------------------------------------------------------------
An alert is a little popup that opens when you visit a page. You can change what is in the popup easily. Hers the alert code:
var Alert1="This is the alert content. (only on one line)";
alert(Alert1);
Now lets take a look at this code. On the first line me make a variable with the content of the alert. Then on the second line we use a code so the alert opens with the content of var Alert1.
Pretty easy, huh?
--------------------------------------------------------------------------------------
Prompts
--------------------------------------------------------------------------------------
Well prompts are just like alerts but you can do more stuff with them. A prompt has a textbox in it so you can ask a question and then the other person can write the answer in the textbox. Lets take a look at this code:
<script>
<!--
var Prompt1="What is your favorite color?","";
prompt(Prompt1);
-->
</script>
On the first line we are calling the script again. Next we hide the script from old browsers. Then on the third line we make a variable named Prompt1. Notice that you will have the text in the first pair of quotes and the text in the texbox in the second pair of quotes. Then on the forth line we write the prompt on the page. Anyways, on the next line we end hiding the script, and then to finish the job we end the script.
Here's another way to make a prompt:
prompt("Whats Up?","")
This way is good for small prompts and will save you room.
--------------------------------------------------------------------------------------
Simple If-Then Statements
--------------------------------------------------------------------------------------
Ok, we won't get into if-then statements because you can do so many stuff with if-then statements. So lets take a look at this code:
<script>
var question=prompt("Whats the password?","Hint: gb0y");
var answer="g0alieb0y";
if(question==answer){
alert("Correct!");
}else{
alert("Nope. Your wrong.");
}
</script>
On the first line we call the script. Next on the second line we make a prompt and the variable. On the third line we made a variable which was the password to get through. So on the forth line we start the if. It says if question (the content put in the second quote by a person) == answer (the variable answer) {. The { symbol starts what will be in the if. Anyways, on the next line we make an alert if you enter the right password writing "Correct!". On the sixth line we end the if with the } symbol then write else which will do something else if you don't do whatever is in the if. So we start the else with the {. Then on the seventh line we make an alert writing "Nope. Your wrong." if you don't enter the correct password. Then we close the script on the last line.
Wow that was alot of text.
Now we will do part of an if-then statement so if the URL is the right URL it will do something.
if (location.href.indexOf('URL')!= -1){
var anything="Pretty simple, right?";
document.write(anything);
}
^ This code is great for proboards! ^
--------------------------------------------------------------------------------------
Thank You!
--------------------------------------------------------------------------------------
Thank you for visiting my first Javascript tutorial! You may repost it but please read the rules at the top before you do
~gb0y