Let's Talk Javascript!!

Discussion in 'Computer Forum' started by g0g0l, Mar 11, 2008.

?

How do you like the thread??

  1. Boriiingggggg .... :p:

    1 vote(s)
    33.3%
  2. Good!

    1 vote(s)
    33.3%
  3. U RocK!! :grin:

    1 vote(s)
    33.3%
  1. g0g0l

    g0g0l ! SpAm

    Computer Forum in IGT is getting boring day by day. So, I have decided to open a javascript thread here. I hope Lord_neo wouldn't mind that :p:

    Why learn Javascript??
    Coz it's cool! It's a browser based language n' u don't need a separate compiler for compiling and running it. It's Object based, so it's easier. It's great language for those who want to learn some computer language but don't know anything yet.

    I call all the IGTians who know javascript to come and put some tutorials here.
    I will also put some!
    Cheers!:beer:
     
  2. g0g0l

    g0g0l ! SpAm

    Tutorial 1

    Important Copyright Info: I hold the copyright for my tutorials and www.indianguitartabs.com is the only website currently, where this content can be viewed. DO NOT COPY PASTE this work without my permission, or nessessory actions will be taken against you.




    Ok.... So This is the first tutorial....
    Please note: My aim is to make you interested about javascript. If you want to learn javascript to the fullest, try searching some tutorials in WWW .
    www.w3schools.com is a great website for learning javascript!



    You can use javascript in Webpages and directly into the url bar also.
    the tag for starting and ending a javascript code in a page is
    Code:
    <script>  </script>
    If you want to execute your code from the url bar....the code will begin with..
    Code:
    javascript:

    HELLO WORLD APPLICATION


    This the first application you have to learn for every languages:eek::

    Suppose you want a webpage to trigger an alert box and display "Welcome to my Website"....

    The code will be...

    Code:
    <script>
    //this is an alert statement
    // tutorial by Sugata
    alert("welcome to my Website...");
    </script>
    
    (or in URL bar:)
    javascript:alert("Welcome to my Webpage");
    
    Let's Examine the code...
    The whole script is inside the <script> tag.
    "//this is an alert statement" is a comment and the browser will not compile that. a comment starts with "//".

    Code:
    //this is a comment..................................
    
    or 
    
    
    /* this is also a comment  this is also a comment
     this is also a comment this is also a comment 
    this is also a comment this is also a comment 
    this is also a comment */
    

    "alert" is an output in javascript. It can either hold some text and numbers, or, it can hold a value for a variable also... In this case it holds some texts already written by you in the quote. Note that almost every line in javascript ends with ";" (not always, but for now, just end each line with it. later you will learn when to use it and when not) and that's really important coz that tells the browser that one command has ended, go to the next command..


    To be continued........
     
  3. g0g0l

    g0g0l ! SpAm

    Tutorial 2

    Important Copyright Info: I hold the copyright for my tutorials and www.indianguitartabs.com is the only website currently, where this content can be viewed. DO NOT COPY PASTE this work without my permission, or nessessory actions will be taken against you.


    Hello World Application With Better Purpose....



    The previous "hello world application" was boring. No matter who opens the page, itll show the same dialog in the alertbox. What if we add the user's name to that?? That will be great isn't it? But, there is a problem. You don't know the name of the person who is going to open the page. Well, you don't have to! Leave it to the user himself! So, you have to take input from the user (that's the user's name) and display out put(your message + the user's name). For that, you need a variable which will store the data (i.e. the user's name) and display it in the alert box. In javascript, We do it by creating variables. The variable should be having a name...

    Remember: A name of a variable can't start with a number. try to start the name with small caps (that's a convention ofcourse)...

    ok so here is the code
    Code:
    <html>
    <head> <title>Name Alert! </title></head>
    <body>
    <script>
    // Hello world application with user input
    // Tutorial by Sugata Sengupta
    
    
    
    
    // First, let's name the variable and asign it to get user's input
    
    var userName = prompt("Please Enter Your Name...");
    
    
    //Now let's put the alertBox working!
    
    alert("Hello " + userName +"! Welcome to IndianGuitarTabs.Com! \n ......");
    //end of code
    
    </script>
    </body>
    </html>
    
    Or... in browser...
    javascript:var userName = prompt("Please Enter Your Name...");alert("Hello " + userName +"! Welcome to IndianGuitarTabs.Com! \n ......");
    

    By now, you would probably wondering what that "var" is about.... It's how we define a variable in Javascript. In javascript, it's really easy to define a variable and the "var" can be any kind of input. In other languages, such as C, this is not so easy. there are lotz of variable kinds, like "int", "float" etc.

    Now let's come to the point. there are lotz of new things to learn.

    1.
    Code:
    var userName = prompt("Please Enter Your Name...");
    
    or you can also write:
    
    var userName = "";
    userName = prompt("Please enter your name...");
    
    In this piece of code, we are creating a variable called userName and storing input in it. This type of input is called Prompt input (there are other kinds inputs also). What this input does is that, it triggers a dialog box which asks for something from you.it takes the input from you and stores that input in the the variable. In this case, it asks your name and stores whatevr you entered in userName.

    TIP: Variables are like jars for storing cookies. Got it?? ;)



    2.
    Code:
    alert("Hello " + userName +"! Welcome to IndianGuitarTabs.Com! \n ......");
    You are familiar with alertBox, but this one is little different. It shows some texts you entered and also shows something that the user had entered. by the + operater, you are adding the variable's value to the string. Remember, when you are adding the value of the variable, don't use quotations. If you write userName within quation( i.e. "useName"), the browser will interpret it as text entered and will display what ever you have entered (it will not display the value). "\n" is an escape character that tells the browser to enter everything after it, in a newline. There are other escape characters also. See the full list Here..


    To be continued...


    If you have anything to ask, don't mind doing it! Just go ahead and post your replies and views here or you can also PM me if you want to.....
     
  4. Super-Admin

    Super-Admin Administrator Staff Member

    guys lets not get into personal attacks. this is computer forum sugata can post anything computer related here as long as no rules are broken.
     
  5. g0g0l

    g0g0l ! SpAm

    ^^Luv ya... Thnx :)
     

Share This Page