Advertisement
viditkothari

file12092012.html

Sep 26th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <script type="text/javascript" language="javascript">
  5.             function reverseString()
  6.                 {
  7.                     var str=document.getElementById('txtBox').value;
  8.                     var strl=str.length;
  9.                     var newStr="";
  10.                     /*
  11.                     // Algorithm to reverse a string #1
  12.                     for(var i=strl;i>0;i--)
  13.                         newStr+=str.charAt(i-1);
  14.                     */
  15.  
  16.                     // Algorithm to reverse a string #2
  17.                     for(var i=0;i<strl;i++)
  18.                        newStr=str.charAt(i) + newStr;
  19.                    document.getElementById('tempDIV').innerHTML=newStr;
  20.                }
  21.        </script>
  22.     </head>
  23.     <body>
  24.         <label for="txtBox">Enter a string : </label><input type="text" name="txtBox" id="txtBox">
  25.         <button type="button" onclick="reverseString()">Reverse</button>
  26.         <div id="tempDIV">
  27.         </div>
  28.     </body>
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement