Simple Machine Codes
April 19, 2024, 09:11:53 pm
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to SMC, the best place for your SMF For Free Codes
 
  Home Help Search Arcade Gallery Affiliates Code Index Staff List Calendar Members Login Register  

Variables

Pages: [1]   Go Down
  Print  
Author Topic: Variables  (Read 1154 times)
0 Members and 1 Guest are viewing this topic.
Agent Moose
Administrator

Offline Offline

Gender: Male
Posts: 2,672



View Profile WWW
« on: June 14, 2007, 09:45:40 pm »

What is a Variable?
A variable is a "container" for information you want to store. A variable's value can change during the script. You can refer to a variable by name to see its value or to change its value.

Ok, How do I use them?
There are two ways you can start out a variable.  You can use this;
Code:
<script>
var name = value
</script>

Or, you can use a shorter way:
Code:
<script>
name = value
</script>

It doesn't matter which one you use.

What exactly would I use them for?
As you read above, variables are "containers".  They can hold HTML, or text, or even other scripts just as Jquery and Javascript codes.

Here is an example of useing a variable for text...
Code:
<script>
name = "Text is being Used"
</script>

Now, that will not show anywhere because it doesn't have anything to make it show.  To make it you would use this...
Code:
<script>
name = "Text is being Used"
document.write(name)
</script>
As you can see, the document.write() is holding the variable name, "name".  So, the text that would show would be "Text is being Used" since that is the text in the variable.

You may use HTML in the variables.  Just one thing you need to remember, you can't use double quotes, you must use Single Quotes.

That is basicly it for the variable tutorial.  That is the best I can do it, I hope you get it and like the tutorial!
Report Spam   Logged

Share on Facebook Share on Twitter

hadesflames
Starter

Offline Offline

Posts: 13


View Profile
« Reply #1 on: June 25, 2007, 06:34:16 pm »

Just one thing you need to remember, you can't use double quotes, you must use Single Quotes.

by that u mean u can not use " u can only use ' or am i wrong?
« Last Edit: June 25, 2007, 06:34:53 pm by hadesflames » Report Spam   Logged
Agent Moose
Administrator

Offline Offline

Gender: Male
Posts: 2,672



View Profile WWW
« Reply #2 on: June 26, 2007, 02:06:59 pm »

you can use ' inside of ".
Report Spam   Logged

hadesflames
Starter

Offline Offline

Posts: 13


View Profile
« Reply #3 on: June 26, 2007, 08:28:32 pm »

then what do u mean by

You may use HTML in the variables.  Just one thing you need to remember, you can't use double quotes, you must use Single Quotes.

?
Report Spam   Logged
Agent Moose
Administrator

Offline Offline

Gender: Male
Posts: 2,672



View Profile WWW
« Reply #4 on: June 27, 2007, 02:44:33 pm »

ok, say I wanted to have an image in an variable:
Code:
var test = "<img src='Image URL here' />"

Notice that I use single quotes in it because there are double quotes used already.  So I couldn't do this:
Code:
var test = "<img src="Image URL here" />"
Because there are Double quotes.

Basicly, when you get farther into learning Javascript, you learn that you can use double quotes, but, you have to find out how to use them in the right way.
Report Spam   Logged

hadesflames
Starter

Offline Offline

Posts: 13


View Profile
« Reply #5 on: June 27, 2007, 05:37:53 pm »

ok. thanks
Report Spam   Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy