JavaScript Lesson 1 : Getting Started

Saturday, July 25th, 2009 | IBM SPSS Professional, Learn HTML, Learn JavaScript, mrStudio

Just so that we can take out HTML templates to the next level we are going to run some articles around the JavaScript language. This article will give you a general understanding of what JavaScript is and what it can do.

So , What is JavaScript?

JavaScript is a scripting language that allows you to add interactivity into your html pages. In general it is used to validate html forms but as we all know Data Collection Server does this for us in a far better way so we use it to make things happen when we do things. For example, show add up the numbers in some text boxes and make sure they don’t go over 100. Some may ask is Java the same as JavaScript and the answer to that is NO, Java is not a scripting language it is a Programming language live C and C++. The key difference between a scripting language and a programming language is that a scripting language is a lightweight programming language and they normal execute without any compiling.
To insert a JavaScript into our HTML page, we use the <script> tag </script>. Inside the <script> tag we use the type attribute to define the scripting language.

So, the <script type=”text/JavaScript”> and </script> tells where the JavaScript starts and ends:

<html>
<body>
<script type="text/JavaScript">
...
</script>
</body>
</html>

The document.write command is a standard JavaScript command for writing output to a page.
One of the first things you want to do when you start to learn any computer language is to display something on the page. The command to do this in JavaScript is document.write. Using this command between the script tags we could for example create an html table.

<html>
<body>
<script type="text/JavaScript">
document.write("<table border=\"1\" width=\"100%\" height=\"100%\">
           <tr><td>HELLO</td><td>WORLD</td></tr></table>");
</script>
</body>
</html>

Some browsers may not support the JavaScript language, if our page was displayed in such a browser they would not see the table with hello world in it they would see the actual code itself. To prevent this from happening we can use the comment html tags ( <!– and a –> )  to hide this code. For example

Just add an HTML comment tag  (end of comment) after the last JavaScript statement, like this:

<html>
<body>
<script type="text/JavaScript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>

You will notice the two forward slashes at the end of comment line (//) This is a JavaScript comment symbol and is used to prevent JavaScript from executing the –> tag. And there you have it you have created your first JavaScript page. The next view articles will tell you how to do some of the other things that will be useful to you when creating Data Collection Surveys.

2 Comments to JavaScript Lesson 1 : Getting Started

admin
14 August, 2009

Thanks for the email Karen, as you will see … we had not escaped the speach marks in the html …

Karen
14 August, 2009

Note on this : If you have quote marks inside script which is itself enclosed in quote marks then you must indicate to the program that these are to be treated as literal characters rather than an end of the instruction. This is done by putting a forward slash / in front of the quote mark which indicates that the next character is to be interpreted literally and not as an instruction.

Leave a comment

Categories

Blog Counts

Search

Archives

PHP Notice: A feed could not be found at http://twitter.com/statuses/friends_timeline/16449757.rss in F:\hshome\anncoona\smarterdimensions.com\Blog\wp-content\plugins\external-rss-reader\inc\simplepie.inc on line 1780