Posts

Showing posts from 2017

image move on right side in java script

Image
JavaScript AnimationClick button below to move the image to right

Click the following to see the result

<html>

   <head>

      <script type="text/javascript">
         <!--
            function myFunc()
            {
               var a = 100;
               try {
                  alert("Value of variable a is : " + a );
               }

               catch ( e ) {
                  alert("Error: " + e.description );
               }
            }
         //-->
      </script>

   </head>

   <body>
      <p>Click the following to see the result:</p>

      <form>
         <input type="button" value="Click Me" onclick="myFunc();" />
      </form>

   </body>
</html>

User-defined objects

<html>
   <head>

   <title>User-defined objects</title>

      <script type="text/javascript">
         function book(title, author){
            this.title = title;
            this.author  = author;
         }
      </script>

   </head>
   <body>

      <script type="text/javascript">
         var myBook = new book("Perl", "Mohtashim");
         document.write("Book title is : " + myBook.title + "<br>");
         document.write("Book author is : " + myBook.author + "<br>");
      </script>

   </body>
</html>

Click the following button to see the result

<html>
   <head>

      <script type="text/javascript">
         <!--
            function getValue(){
               var retVal = prompt("Enter your name : ", "your name here");
               document.write("You have entered : " + retVal);
            }
         //-->
      </script>

   </head>

   <body>
      <p>Click the following button to see the result: </p>

      <form>
         <input type="button" value="Click Me" onclick="getValue();" />
      </form>

   </body>
</html>

Click the following button to see the result:

<html>
   <head>

      <script type="text/javascript">
         <!--
            function Warn() {
               alert ("This is a warning message!");
               document.write ("This is a warning message ohh bay!");
            }
         //-->
      </script>

   </head>
   <body>
      <p>Click the following button to see the result: </p>

      <form>
         <input type="button" value="Click Me" onclick="Warn();" />
      </form>

   </body>
</html>

set a browser name and redirected link

<html>
   <head>

      <script type="text/javascript">
         <!--
            var browsername=navigator.appName;
            if( browsername == "Netscape" )
            {
               window.location="http://www.google.com";
            }
            else if ( browsername =="Microsoft Internet Explorer")
            {
               window.location="http://www.yahoo.com";
            }
            else
            {
               window.location="http://www.arenanagpur.com";
            }
         //-->
      </script>

   </head>

   <body>
   </body>
</html>

auto redirected page in java script

auto redirected
<html>
   <head>

      <script type="text/javascript">
         <!--
            function Redirect() {
               window.location="http://www.google.com";
            }

            document.write("You will be redirected to main page in 10 sec.");
            setTimeout('Redirect()', 10000);
         //-->
      </script>

   </head>

   <body>
   </body>
</html>

use window dot location in java script

Click the following button, you will be redirected to home page. <html>
   <head>

      <script type="text/javascript">
         <!--
            function Redirect() {
               window.location="http://www.google.com";
            }
         //-->
      </script>

   </head>

   <body>
      <p>Click the following button, you will be redirected to home page.</p>

      <form>
         <input type="button" value="Redirect Me" onclick="Redirect();" />
      </form>

   </body>
</html>

Set Cookes in java script

Set Cookes <html>
   <head>

      <script type = "text/javascript">
         <!--
            function WriteCookie()
            {
               if( document.myform.customer.value == "" ){
                  alert("Enter some value!");
                  return;
               }
               cookievalue= escape(document.myform.customer.value) + ";";
               document.cookie="name=" + cookievalue;
               document.write ("Setting Cookies : " + "name=" + cookievalue );
            }
         //-->
      </script>

   </head>

   <body>

      <form name="myform" action="">
         Enter name: <input type="text" name="customer"/>
         <input type="button" value="Set Cookie" onclick="WriteCookie();"/>
      </form>

   </body>
</html>

using onmouseover in javascript

onmouseover 





<html>
   <head>

      <script type="text/javascript">
         <!--
            function over() {
               document.write ("Mouse Over");
            }

            function out() {
               document.write ("Mouse Out");
            }

         //-->
      </script>

   </head>
   <body>
      <p>Bring your mouse inside the division to see the result:</p>

      <div onmouseover="over()" onmouseout="out()">
         <h2> This is inside the division </h2>
      </div>

   </body>
</html>

using onsubmit event and post method in javascript

onsubmit event and post method 
<html>
   <head>

      <script type="text/javascript">
         <!--
            function validation()
         {
               all validation goes here
               .........
               return either true or false
            }
         //-->
      </script>

   </head>
   <body>

      <form method="POST" action="ex1.html" onsubmit="return validate()">
         .......
         <input type="submit" value="Submit" />
      </form>

   </body>
</html>

Set the variable to different object and then try...

variable to different object <html>
   <body>

      <script type="text/javascript">
         <!--
            var index;
            document.write("Navigator Object Properties<br /> ");

            for (index in anurag) {
               document.write(aProperty);
               document.write("<br />");
            }
            document.write ("Exiting from the loop!");
         //-->
      </script>

      <p>Set the variable to different object and then try...</p>
   </body>
</html>

Set the variable to different value and then try..

Set the variable to different value <html>
   <body>

      <script type="text/javascript">
         <!--
            var age = 20;

            if( age > 15 ){
               document.write("<b>Qualifies for driving</b>");
            }
         //-->
      </script>

      <p>Set the variable to different value and then try...</p>
   </body>
</html>

Set the variables to different values and different operators and then try...

different values and different operators
<html>
   <body>

      <script type="text/javascript">
         <!--
            var a = 10;
            var b = 20;
            var linebreak = "<br />";

            document.write("(a && b) => ");
            result = (a && b);
            document.write(result);
            document.write(linebreak);

            document.write("(a || b) => ");
            result = (a || b);
            document.write(result);
            document.write(linebreak);

            document.write("!(a && b) => ");
            result = (!(a && b));
            document.write(result);
            document.write(linebreak);
         //-->
      </script>

      <p>Set the variables to different values and different operators and then try...</p>
   </body>
</html>

Set the variables to different values and different operators and then try...

different values and different operators
<html>
   <body>

      <script type="text/javascript">
         <!--
            var a = 10;
            var b = 20;
        var c=10;
            var linebreak = "<br />";

            document.write("(a == b) => ");
            result = (a == b);
            document.write(result);
            document.write(linebreak);

            document.write("(a < b) => ");
            result = (a < b);
            document.write(result);
            document.write(linebreak);

            document.write("(a > b) => ");
            result = (a > b);
            document.write(result);
            document.write(linebreak);

            document.write("(a != b) => ");
            result = (a != b);
            document.write(result);
            document.write(linebreak);

            document.write("(a >= b) => ");
            resu…

Set the variables to different values and then try...

Set variables
<html>
   <body>

      <script type="text/javascript">
         <!--
            var a = 33;
            var b = 10;
            var c = "Test";
            var linebreak = "<br />";

            document.write("a + b = ");
            result = a + b;
            document.write(result);
            document.write(linebreak);

            document.write("a - b = ");
            result = a - b;
            document.write(result);
            document.write(linebreak);

            document.write("a / b = ");
            result = a / b;
            document.write(result);
            document.write(linebreak);

            document.write("a % b = ");
            result = a % b;
            document.write(result);
            document.write(linebreak);

            document.write("a + b + c = ");
            result = a + b + c;
            document.write(result);
          …

how to Declare a global variable and local variable in java script

global variable and local variable
<html>
   <body onload = checkscope();>
      <script type = "text/javascript">
         <!--  
            function checkscope( ) {
      var myVar = "global"; // Declare a global variable
                var myVar = "local";  // Declare a local variable

               document.write(myVar);
            }
         //-->
      </script>
   </body>
</html>

how to use document dot write in java script

document dot write function
<html>
   <body>

      <script language="javascript" type="text/javascript">
         <!--
            document.write("Hello World!")
         //-->
      </script>

      <noscript>
         Sorry...JavaScript is needed to go ahead.
      </noscript>

   </body>
</html>

declaring global variable and accessing global variable

Declaring and Accessing
<html>
<head>
<script>
function m(){
window.value=100;//declaring global variable by window object
}
function n(){
alert(window.value);//accessing global variable from other function
}
n();
</script>
</script>
</body>
</html>

using Function

Function
<html>
<head>
<script>
var value=50;//global variable
function a(){
alert(value);
}
function b(){
alert(value);
}
a();
</script>
</script>
</body>
</html>

How to use global variable

Global Variable 

<html>
<head>

<script>
var data=200;//global variable

function a()
{
document.writeln(data);
}
function b(){
document.writeln(data);
}
a();//calling JavaScript function
b();  
</script>
</body>
</html>

using variables in Java Script

using variables in Java Script
<html>
<head>
<script>
var x = 10;
var y = 20;
var z=x+y;
document.write(z);
</script>
</body>
</html>

Click Event use with Alert Function In Java Script

Click Event use with Alert Function

<html>
<head>
<script type="text/javascript">
function msg(){
 alert("Hello Javatpoint");
}
</script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>

Hoe to use Alert Function In java script

Alert Function
<html>
<body>
<script type="text/javascript">
 alert("Hello");
</script>  
</body>
</html>

Click the buttons below to handle animation

Java script Animation Click the buttons below to handle animation <html>    <head>       <title>JavaScript Animation</title>       <script type="text/javascript">          <!--             var imgObj = null;             var animate ;             function init(){                imgObj = document.getElementById('myImage');                imgObj.style.position= 'relative';                 imgObj.style.left = '0px';              }             function moveRight(){                imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';                animate = setTimeout(moveRight,20); // call moveRight in 20msec             }             function stop(){                clearTimeout(animate);                imgObj.style.left = '0px';              }             window.onload =init;          //-->       </script>    </head>       <form>          <img id="myImage" src=&quo…

Click button below to move the image to right

Click button below to move the image to right.
Little Animation using java script.
This is going to be moving the right side of the image from Java Script or HTML, every click.
<html>    <head>       <title>JavaScript Animation</title>       <script type="text/javascript">          <!--             var imgObj = null;             function init(){                imgObj = document.getElementById('myImage');                imgObj.style.position= 'relative';                 imgObj.style.left = '0px';              }             function moveRight(){                imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';             }             window.onload =init;          //-->       </script>    </head>    <body>       <form>          <img id="myImage" src="Suicide-Squad.jpg" />          <p>Click button below to move the image to right</p>     …

java script book in PDF format

What is JavaScript? JavaScript is a scripting language that enables web developers/designers to build more functional and interactive websites.  Common uses of JavaScript include: Alert messages  Popup windows  Popup windows  Dynamic drop down menus  Form validation  Displaying date/time  JavaScript usually runs on the client-side(the browser's side), as opposed to server-side(on the web server). One benefit of doing this is performance. On the client side, JavaScript is loaded into the browser and can run as soon as it is called.

*---java script book in PDF format--*