Skip to main content

Simple Javascript

JavaScript
Why is JavaScript special?

JavaScript generates DYNAMIC content.

JavaScript gives life to your content by animating certain parts and adds interactivity to it.Weren't the hyperlinks enough,why do I need more interactivity?

Let us map this to the concept of writing in a book once again.

It is pretty hard to imagine interactivity so let us take an example we are aware of i.e. cartoons we see animating in the television.

Imagine one day you open your book and suddenly the objects start animating like the cartoons from your favorite bestselling television series.

Similarly, JavaScript does the same thing to the content.

This is just the beginning, it gets more deeper and denser by allowing you to have complete control of your page content with Server Side Scripting.

In this post we have just begun with some simple functional interactivity.

We have some simple functions in JavaScript like:
1.     alert();
2.     document.write();

The alert() function in JavaScript alerts the user by displaying a message with a small window.You also get a small button to input your reaction.Hence the interactivity.

The document.write() function in JavaScript prints the content on the webpage.The document.write can also take multiple line content using the "\n".

The program below showcases the functionality delivered by the alert() and document.write() functions in a simple JavaScript program.


The declaration of variables in the JavaScript is much simpler than compared to other languages. We shall look at the variable -creation and assignment along with the prompt() function in the next post.

1:  <?xml version = "1.0" encoding="utf-8"?>
2:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3:  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
4:  <html xmlns="http://www.w3.org/1999/xhtml">  
5:  <head>  
6:  <title>Simple Javascript</title>  
7:  </head>  
8:  <body>  
9:  <script>  
10:  alert("This website belongs to me");  
11:  alert("Hello I am Javascript, Let us begin a dynamic journey");  
12:  document.write("I can write on the webpage");</script>  
13:  </body>  
14:  </html>  


The JavaScript uses the DOM model to provide such flexibility for the designer pick up specific tags i.e. components on the web page and design them dynamically. In the above simple JavaScript program the DOM is not completely shown as the script tag is used and the JavaScript is written as a part of the HTML document itself.The JavaScript document can be written separately as well and referenced by the link tag as the src attribute in the head section of the HTML document.

The code if written separately using the JavaScript and the HTML document would be as below.

The HTML code firstly would be as follows:
Here the link tag with the src attribute in HTML is demonstrated.
1:  <?xml version = "1.0" encoding="utf-8"?>
2:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3:  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
4:  <html xmlns="http://www.w3.org/1999/xhtml">  
5:  <head>  
6:  <title>Simple Javascript</title>  
7:  </head>  
8:  <body>  
9:  </body>  
10:  </html>  

The above file is to be saved separately as a .html extension file.

The next file is to be written containing the JavaScript function exclusively.One can also notice that this file does not have the script tag, The name of the file is the most important thing in this method along with the saved extension type which is .js type file extension.


In the above link tag one may also notice that this tag does not have a closing tag such as </link>. Everything is enclosed in a single tag from <link ....>.



Comments

Popular posts from this blog

Social Gaming

Gaming is just fun. Fun can a moment of joyous experience that makes us feel light hearted, wow a whole computer sector industry based on the various user experiences. This industry drives it's source on the basis of the gamers imaginative drive.The more imaginative the gamer can get the more fun and experience they feel. But has anyone wondered what are the most addictive games across the web commonly written in. They are generally written in our day to day web programming languages such as HTML,CSS, JavaScript,Ajax and SQL like databases are used to store the user records Nowadays the gaming has evolved to reach a larger perspective of users utilizing the social networks such as Facebook,Twitter,Orkut,Google+ etc Why does one need social networks for gaming, why do they matter? The social networks in-fact have created new business segments and provided a new experience to have fun as the end product and brought us to the social gaming segment. Social Gaming Social...

OpenGL Games

OpenGL is technology that enables the user to create graphics by literally joining dot by dot (technically pixel by pixel). The Open GL graphics libraries enable the user to use the language of their own preference such as C,C++,Java,Python and so on to create the graphics and animate their still pictures. So which are the games that are built using the OpenGL libraries. There are many old as well as new games that have been built upon the OpenGL graphics libraries.They are as well as heavy duty FPS games as well as the day to day addictive mobile games. Some of them are as enlisted below. Fans of these games may be many but do you know that these were built using the OpenGL libraries. 1) AngryBirds                                                           Angry Birds   Who does not know the AngryBirds game? Angry Birds ...

SMITE Open Beta Review

The developers of Global Agenda and Tribes: Ascend have yet another major offering to keep you glued to your screens, now providing an opportunity to play 'Mythological Godlike avatars' in their latest offering called Smite. Placing yourself in the shoes of the 'Almighty' or a bunch of them 'All Mighty' if I might say, itself should give you an idea of what herculean tasks you would be asked to handle. The feeling of 'omnipotence' brings an exceptional nature to this game. Limitless flow of power is just a part of the experience, but having an ultimate command over it and other such myriad abilities can seal the deal for you. Spell slingers, knights in shining armor, snoopy hunters, shady assassins, brute warriors are the new God lineages here. Outgrowing heightened expectations is the least things you should expect as this mythological battlefield resides over the whole wide internet. Teleporting, Flying, Sprinting, and digging, you will have ...