Post by Peter on Jun 18, 2004 11:36:19 GMT
A brief overview of javascript:
You start with <script> and end with </script> every time.
It is common to use cloaking from older browsers by adding <!-- to the beginning and //--> or just --> at the end
Comments
They are parts of a script that are not read by the Javascript console, they are for humans to read and are completely ignored by the browser. There are 2 ways of writing them:
// This comment lasts for one line
/* This comment last until I end it with this: */
Variables
Variables are used to hold data that can change each time a page loads. Variables are often used to make it so that you don't have to write something repeated times or to make it easier on people who don't understand how to edit every part. To declare a variable you simply write the var before it. Like this:
var ok = "That's ok"
To understand javascript you must know the difference between a string, a number and several other different values.
The ones I use the most are strings, numbers, and boolean (I think) values. Strings are like sentences, however whenever you write a string you must have it some form of quotes, like this:
"This is a string in double quotes"
'This is a string in single quotes'
numbers are just written like they are, for example:
5
boolean values are true or false values and can ussualy be written in one of 2 ways (I'm pretty sure):
1. True or false
2. 1 (true) or 0 (false)
Some commands
if(){}
for(){}
alert()
function blah(){}
prompt()
confirm()
write()
For if(){} you write the statement that you want to check to see if it's true, then in the brackets you write what you want it to do if it's true.
An example:
var h =5
if(h == 5){
document.write(h)
}
Note: I didn't use one = sign, I used two (==). One equal sign is saying what something equals, 2 is comparing.
Javascript always starts counting from 0 and you need to remember that. It is a major flaw in alot of scripts.
Arrays
An array is something that holds multiple variables
An example:
var hey = new Array("Hey',"Hello","Hi","Wassup")
or:
var hey = new Array
hey[0] = "Hey"
hey[1] = "Hello"
That's pretty much saying the 0th hey is "Hey" and the first hey is "Hello"
Functions
function sayIt(text){
alert(text)
}
To call the function you would do this:
sayIt("hello")
This would make an alert with "hello" in it, you could change hello to whatever you want. However, you wouldn't use functions for something stupid like that. Instead you would do. Instead you'd do something like this:
document.form.checkbox.onChange = "javascript: checkIt(this)"
Then the function would look like this:
function sayIt(it){
if(it.checked){
document.form.checkbox2.checked = true
}}
Alert, Confirm, Prompt
These are basic, preset functions.
Alert: alert("Hey") \\Makes an alert that says: Hey
Confirm: confirm("Are you sure you wish to delete?")
Makes a confirm alert type thing. If it is chosen yes, then it will continue, otherwise it will go back.
Prompt: var size = prompt("What size would you like the image","#x#")
The "" set is the text, the second is the default in the prompt.
Later you can call their answer by using the size variable.
Using an If
an if() statement is made when they are several possibilities, but you need a certain one. Or to check a value, and do something if it is, or isn't there.
Here is one for making it that something only happens on one page instead of pages, because the main H&F applies to many pages:
if(location.href.indexOf(/action=profile&username)){
document.write("heh")
}
The difference between write() and adding to a TD or something else
document.write("Can be used to") write something where the script is located. Like in the affiliates code we use. It writes it in there, no need to obtain properties of a TD and insert it there.
For adding something to something where a script cannot be placed should be used like this:
var TD = document.getElementsByTagName('td');
TD[5].innerHTML += 'This is the menu'
or adding to a form could go like this:
document.postmodify.message.value += "This is the message area"
You start with <script> and end with </script> every time.
It is common to use cloaking from older browsers by adding <!-- to the beginning and //--> or just --> at the end
Comments
They are parts of a script that are not read by the Javascript console, they are for humans to read and are completely ignored by the browser. There are 2 ways of writing them:
// This comment lasts for one line
/* This comment last until I end it with this: */
Variables
Variables are used to hold data that can change each time a page loads. Variables are often used to make it so that you don't have to write something repeated times or to make it easier on people who don't understand how to edit every part. To declare a variable you simply write the var before it. Like this:
var ok = "That's ok"
To understand javascript you must know the difference between a string, a number and several other different values.
The ones I use the most are strings, numbers, and boolean (I think) values. Strings are like sentences, however whenever you write a string you must have it some form of quotes, like this:
"This is a string in double quotes"
'This is a string in single quotes'
numbers are just written like they are, for example:
5
boolean values are true or false values and can ussualy be written in one of 2 ways (I'm pretty sure):
1. True or false
2. 1 (true) or 0 (false)
Some commands
if(){}
for(){}
alert()
function blah(){}
prompt()
confirm()
write()
For if(){} you write the statement that you want to check to see if it's true, then in the brackets you write what you want it to do if it's true.
An example:
var h =5
if(h == 5){
document.write(h)
}
Note: I didn't use one = sign, I used two (==). One equal sign is saying what something equals, 2 is comparing.
Javascript always starts counting from 0 and you need to remember that. It is a major flaw in alot of scripts.
Arrays
An array is something that holds multiple variables
An example:
var hey = new Array("Hey',"Hello","Hi","Wassup")
or:
var hey = new Array
hey[0] = "Hey"
hey[1] = "Hello"
That's pretty much saying the 0th hey is "Hey" and the first hey is "Hello"
Functions
function sayIt(text){
alert(text)
}
To call the function you would do this:
sayIt("hello")
This would make an alert with "hello" in it, you could change hello to whatever you want. However, you wouldn't use functions for something stupid like that. Instead you would do. Instead you'd do something like this:
document.form.checkbox.onChange = "javascript: checkIt(this)"
Then the function would look like this:
function sayIt(it){
if(it.checked){
document.form.checkbox2.checked = true
}}
Alert, Confirm, Prompt
These are basic, preset functions.
Alert: alert("Hey") \\Makes an alert that says: Hey
Confirm: confirm("Are you sure you wish to delete?")
Makes a confirm alert type thing. If it is chosen yes, then it will continue, otherwise it will go back.
Prompt: var size = prompt("What size would you like the image","#x#")
The "" set is the text, the second is the default in the prompt.
Later you can call their answer by using the size variable.
Using an If
an if() statement is made when they are several possibilities, but you need a certain one. Or to check a value, and do something if it is, or isn't there.
Here is one for making it that something only happens on one page instead of pages, because the main H&F applies to many pages:
if(location.href.indexOf(/action=profile&username)){
document.write("heh")
}
The difference between write() and adding to a TD or something else
document.write("Can be used to") write something where the script is located. Like in the affiliates code we use. It writes it in there, no need to obtain properties of a TD and insert it there.
For adding something to something where a script cannot be placed should be used like this:
var TD = document.getElementsByTagName('td');
TD[5].innerHTML += 'This is the menu'
or adding to a form could go like this:
document.postmodify.message.value += "This is the message area"
Tutorial By: Forte