• Streams & Subjects

    Streams & Subjects

    Get detailed description of each and every topic with proper examples including text, images and videos.

  • Latest Technologies

    Latest Technologies

    Know more about the latest and new emerging technologies and boost your knowledge.

  • Programming

    Programming

    Don't learn just codes and syntax, instead learn the best and efficient way of coding.

  • Technologies

    New Technologies

    Get instant and relevant updates of the latest emerging technologies of lots of streams including web, clouds, virtualization, etc.

  • Freewares

    Freewares

    Download free trials and freewares of various fields and check out their efficiency before buying.

  • Multimedia

    Multimedia

    Learn techniques to design amazing and creative multimedia designs and characters including 2D & 3D layout with rendering.

Showing posts with label Javascript Tutorial. Show all posts
Showing posts with label Javascript Tutorial. Show all posts

Syntax

How to write javascript

If you have ever used CSS before, you will find the whole part about including JavaScript will be a lot simpler to grasp. Here are Tizag's three important steps you should always follow when creating or using someone else's JavaScript code:

  • Use the script tag to tell the browser you are using JavaScript
  • Write or download some JavaScript
  • Test the script!

There are so many different things that can go wrong with a script, be it human error, browser compatibility issues, or operating system differences. So, when using JavaScript, be sure that you test your script out on a wide variety of systems and most importantly, on different web browsers.


Your first javascript script

To follow the classic examples of many programming tutorials, let's use JavaScript to print out "Hello World" to the browser. I know this isn't very interesting, but it will be a good way to explain all the overhead required to do something in JavaScript.


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

Output:
Hello World!

Our first step was to tell the browser we were using a script with the <script> tag. Next we set the type of script equal to "text/JavaScript". You may notice that doing this is similar to the way you specify CSS, which is "text/css".

Next, we added an optional HTML comment that surrounds our JavaScript code. If a browser does not support JavaScript, it will not display our code in plain text to the user! The comment was ended with a "//-->" because "//" signifies a comment in JavaScript. We add that to prevent a browser from reading the end of the HTML comment in as a piece of JavaScript code.


Javascript document.write

The final step of our script was to use a function called document.write, which writes a string into our HTML document. document.write can be used to write text, HTML, or a little of both. We passed the famous string of text to the function to spell out "Hello World!" which it printed to the screen.

Do not worry if you don't completely understand how document.write works, as we will be discussing functions in a later lesson.


Syntax

Looking at our JavaScript code above, notice that there is no semicolon at the end of the statement "document.write(Hello World!)". Why? JavaScript does not require that you use semicolons to signify the end of each statement.

If you are an experienced programmer and prefer to use semicolons, feel free to do so. JavaScript will not malfunction from ending semicolons. The only time it is necessary to use a semicolon is when you choose to smash two statements onto one line(i.e. two document.write statements on one line).



Read more

Introduction

Javascript Tutorial

JavaScript has been around for several years now, in many different flavors. The main benefit of Javascript is to add additional interaction between the website and its visitors with just a little extra work by the web developer. Javascript allows industrious web masters to get more out of their website than HTML and CSS can provide.
By definition, JavaScript is a client-side scripting language. This means the web surfer's browser will be running the script. The opposite of client-side is server-side, which occurs in a language like PHP. PHP scripts are run by the web hosting server.
There are many uses (and abuses!) for the powerful JavaScript language. Here are a few things that you may or may not have seen in your web surfing days:
  • Clocks
  • Mouse Trailers (an animation that follows your mouse when you surf a site)
  • Drop Down Menus
  • Alert Messages
  • Popup Windows
  • HTML Form Data Validation

Tutorial Overview

Before you begin this tutorial, you should have basic knowledge of HTML. Check out our Beginner and HTML tutorials to brush up on the basics.
This tutorial will cover the basics of JavaScript, from where to place your JavaScript all the way to making your own JavaScript functions. Also, there will be some good programming practice tips throughout this tutorial.
We recommend that you read a few lessons a day and practice what you have learned. This will help you to absorb the material more readily than if you blasted through the entire tutorial in one sitting!
If you are already good in Javascript then you can find sample programs here


Read more