LinkExchange Member
.bottom
Some beginning JavaScript
Here is some basic JavaScript to liven up your page.
JavaScript is a completely different than HTML. If you make mistakes in your scripts the whole script will probably fail to run and may cause other problems. I am on webtv wich is not capable of all JavaScript so my help will be limited to what I have gotten to work.
The first thing you must know is where to place it in your page.
It is not necessary but recommended because certain
browsers require it to be right after the </title> and
before the <head> tag.
Scripts will be placed through out a page on further pages. I have a script down by my guestbooks. Functions wich are described later on should always be up in the head.
Now for the actual beginning of the script.
Now for the entire script.
alert("Welcome to my page");
// End Script -->
You can also place some comments that would not be seen unless the source code is being viewed.
one line comments
// comments not longer than on line
comment blocks
/* comments as long as you want
like credits. script written by
Permission to use if you
sell you soul etc
*/
Making it more interactive
Now you know how to make a simple pop-up. Here is how you get the page to ask for some personal input
var name = prompt("What is your name?","Name here");
This will put up a prompt asking the person for there name. If this box were to pop up it would have the words name here already in the box. You could leave the space between the second set of qoutes blank if you don't want a default value already in the box.
The results of the prompt will be stored in the variable name You could use whatever word or letter you want in the place of name, except for certain words that are already used by JavaScript like alert or var and others. I'll put a link to the list of reserved words when I remember where I wrote the address at. A variable begins with a letter and can contain numbers and the underscore such as var viewer_name=prompt("What is your name","");. It is best to stick with variable names that help remind you what is stored in it. When you start writing longer scripts you'll want to be able to keep track of what is stored where.
Now how to use the value stored in name in your pop-up
Here is an addition to the alert statement
alert("Hello, "+name);
I have placed the variable name within the alert box. The text of the alert is within qoutes, the variable is outside of the qoutes and must have the plus sign before it.
You could continue the text after the variable as
follows
alert("Hello, "+name+" Welcome to my page");
You'll notice I made spaces within the qoutes otherwise you'll get Hello,BobWelcome to my page. Instead of Hello, Bob Welcom to my page
So now Here is the complete script for a prompt followed by a pop-up
If you want to control when a new line starts add this to your alert
alert("Hello, "+name+"\nWelcome to my page");
I put the \n after the second qoute so that right after the Hello Bob A new line would start. Welcome to my page instead of having the browser choose when to make the break wich can make your alert look funny
Try you hand at editing a short welcome script in. A sample script is below the editing window. Copy it to the window if you wish, and try changing the way the question and alert is worded. Try changing the place of the variable name and anything else you wish to try. If you like what you have made copy it and enter it into your page editor.
Lesson 1
Once you've got that down go on to
On to even more
interactivity
.
Sign my GuestBook
View my GuestBook
Read my DreamBook
Sign my DreamBook
Quiz
of the Week
An interactive weekly quiz. Some of wich I write
myself
MEMBER of the POD | | |