Monday 3 July 2017

Javascript basic tutorial

Javascript basic tutorial

Let's start our journey into the learning of JavaScript by typing in the following HTML code. We will add to it and eventually wind up with a working clock similar to the one above. Of course it will take us a several lessons to get there because we first need to learn the basics.

 <HTML>
 <HEAD>
 <TITLE>Our First Script</TITLE>
 </HEAD>
 <BODY>
 <CENTER>
 <H1>Our First Script</H1>
 </CENTER>
 <P>Today is
 </BODY>
 </HTML>

Save this code as script1.html.  It looks something like this when we load it into our browser by using File/Open on the menu.

Our First Script
Today is



Not very exciting! Lets add some JavaScript to our code. Add the following script after the line <P>Today is

 <SCRIPT Language="JavaScript">
 var today = new Date()
 document.write(today)
 </SCRIPT>

Your html code should now look like this.

 <HTML>
 <HEAD>
 <TITLE>Our First Script</TITLE>
 </HEAD>
 <BODY>
 <CENTER>
 <H1>Our First Script</H1>
 </CENTER>
 <P>Today is
 <SCRIPT Language="JavaScript">
 var today = new Date()
 document.write(today)
 </SCRIPT>
 </BODY>
 </HTML>

Save this script and reload it into you browser. It should render something like this:

Our First Script
Today is Mon Jul 03 2017 15:54:47 GMT+0530 (India Standard Time)




Still not real exciting, but remember this is only our first script and does demonstrate something you can't do with plain HTML.

No comments:

Post a Comment

IE7 Issues Text Indent

                 Unfortunately IE 7 is still widespread among the users hence while theming we have to give special importance to the grea...