Since javascript isn't HTML, you will need to let the browser know in advance when you enter javascript to an HTML page. This is done using the <scrypt> tag.
The browser will use the <scrypt> type="text/javascript"> and </scrypt> to tell where javascript starts and ends.
<body> <script type="text/javascript"> alert("Welcome to my world!!!"); </script> </body> </html>
The word alert is a standard javascript command that will cause an alert box to pop up on the screen. The visitor will need to click the "OK" button in the alert box to proceed.
By entering the alert command between the <scrypt type="text/javascrypt"> and </scrypt> tags, the browser will recognize it as a javascript command.
If we had not entered the <scrypt> tags, the browser would simply recognize it as pure text, and just write it on the screen.
You can enter javascript in both the <head> and <body> sections of the document. In general however, it is advisable to keep as much as possible in the <head> section.
Knowing that javascript needs to be entered between <scrypt> tags, is a start. But there are a few other things you need to know before writing your first javascript:
Javascript lines end with a semicolon. You may have noticed from the example on the previous page that javascript lines end with a semicolon. You can easily put all your javascript on a single line without destroying the performance of it. However, you would destroy the overview of your script so it is not advisable.
Always put the text within " ". When entering text to be handled by javascript, you should always put the text within " ". If you forget to enclose your text in " ", javascript will interpret your text as being variables rather than text. In the next section you will learn why this would cause an error to your script.
Capital letters are different from lowercase letters. You should always remember that capital letters are different from lowercase letters. This means that when you write commands in javascript, you need to type capital letters in the correct places, and nowhere else.
Incorrect capitalization is probably the most common source of error for javascript programmers on all levels!!
Now consider this example:
Instead of having javascript write something in a popup box we could have it write directly into the document.
The document.write is a javascript command telling the browser that what follows within the parentheses is to be written into the document.
Note: When entering text in javascript you need to include it in " ".
The script in the example would produce this output on your page:
Hello Cruel World!
As you can see, javascript simply writes the text to where the script is placed within the HTML codes.
An interesting aspect is that you can write all kinds of HTML tags to webpages with the document.write method.
For instance, if you wanted to make a long table that compared Fahrenheit and Celsius, instead of actually typing all the values into the table, you could have javascript calculate the values and write the table to the document.
The problem with the cap once taken away hours of work time and years of life. I could not understand why everything is buggy, seemingly the algorithm was correct. Then read on a forum that should be more careful ... Sometimes the process stopper with such trifles.
The comments are owned by the poster. We aren't responsible for its content. Only registered members may comment on articles.