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>
<html>
<head>
    <title></title>
  <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()
    {
        //alert(document.getElementById("txtusername").value);
        //    document.getElementById("txtusername1").value = document.getElementById("txtusername").value;

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

        document.bgColor = "blue";

       
    }
    
</script>

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

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


</body>
</html>

 

Add a Comment

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