Introduction to javascript

Javascript is a client-side scripting language. This means, the code written in javascript is run locally on a user’s browser and is not run on the remote server. The following file introduces code of javascript. A javascript function is called against onclick property of a button. The function assigns value of first textbox to the other textbox. The code is also changing the background color of the page. The javascript supports single line and multiline comments as shown in the <script></script> tags. You can uncomment the commented portion of code to see its behavior.

<!DOCTYPE html>
  <meta charset="utf-8" />

<script language="javascript" type="text/javascript">
    this is multiline comment
    // this is single line
    //  document.write("<input type='text' />");

    //   alert("hello");

    // confirm("are you sure?");

    function ShowUserName()
        //    document.getElementById("txtusername1").value = document.getElementById("txtusername").value;

        // alert(document.links[1].href);

        document.bgColor = "blue";


    Source: <input id="txtusername" name="txtusername" 
           type="text" value="Faisal"  />
    <br /><br />

    Target: <input id="txtusername1" name="txtusername1"
                   type="text" />
    <br /><br />
    <a href="">Google</a> <br /><br />
    <a href="">Yahoo</a><br /><br />
    <input id="btnshow" name="btnshow" type="button" 
           value="Click Here" onclick="ShowUserName();" />



Add a Comment

Your email address will not be published. Required fields are marked *