Find us on Google+ Kill the code: js
Showing posts with label js. Show all posts
Showing posts with label js. Show all posts

Sunday, 11 March 2012

Palindrome validation in Javascript

Preview :


New Web Project Enter a string :


Code :

<html>

    <head>

        <title>New Web Project</title>

    </head>

    <body>

     

     <script type="text/javascript">

      function pal() {

       var b;

       var a = document.getElementById('str');

       var c1 = a.value.length;

       var flag=0;

       for(b=0; b<c1/2;b++) {

        if(a.value.charAt(b)==a.value.charAt(--c1)) {

         flag=0;

        }

        else {

          flag=1;
          break;

        }

       }

       if(flag!=1) {

        document.getElementById("lbl").innerHTML = "The string is Palindrome";

        document.getElementById("fnt").style.color = "green";

       }

       else {

        document.getElementById("lbl").innerHTML = "The string is not Palindrome";

        document.getElementById("fnt").style.color = "red";

       }

       return;

      }

      

      function foc() {

       var a = document.getElementById("str");

       if(a.value == "enter string...") a.value = "";

       return;

      }

      function foc_lost() {

       var b = document.getElementById("str");

       if(b.value == "") b.value = "enter string...";

       return;

      }

     </script>

     

     

     

     

        Enter a string : <input type="text" name="string" id="str" value="enter string..." onfocus="return foc()" onblur="return foc_lost()"/>

        <input type="button" onclick="return pal()" value="Check"/><br />

        <font id="fnt"><label id="lbl"></label></font>

    </body>

</html>

Sunday, 4 March 2012

Image changer in Javascript using Z-Index

Preview :
New Web Project







Code :







<html>
    <head>         <title>New Web Project</title>         <style type="text/css">         #block img {         position:absolute;         left:10px;         top:10px;         z-index:0;         }         #but {         margin-left: 300px;         margin-top: 300px;         }         </style>     </head>     <body>     <script type="text/javascript">     var b = 0;     function change() {     b++;     var a = document.getElementById(b%5);     a.style.zIndex = b;     return;     }     function call() {     var c = setInterval("change()",1000);     return;     }     </script>         <div id="block">         <img src="4.png" id="4"/>         <img src="3.png" id="3"/>         <img src="2.png" id="2"/>         <img src="1.png" id="1"/>         </div>         <input type="button" id="but" onclick="return call()" value="change">     </body> </html>

Thursday, 1 March 2012

Image Swaping in Javascript

Preview : 


New Web Project




Code :




<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
    </head>
    <body>
    <script type="text/javascript">
    function swap() {
    var t = document.getElementById("i1").src;
    document.getElementById("i1").src = document.getElementById("i2").src;
    document.getElementById("i2").src = t;
    return;
    }
    </script>
        <img src="1.png" id="i1"/>
        <img src="2.png" id="i2"/>
        <input type="button" id="but" value="swap" onclick="return swap()"/>
        <a href="http://killthecode.blogspot.in">For more programs click here</a>
    </body>
</html>