Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" language="javascript">
- function reverseString()
- {
- var str=document.getElementById('txtBox').value;
- var strl=str.length;
- var newStr="";
- /*
- // Algorithm to reverse a string #1
- for(var i=strl;i>0;i--)
- newStr+=str.charAt(i-1);
- */
- // Algorithm to reverse a string #2
- for(var i=0;i<strl;i++)
- newStr=str.charAt(i) + newStr;
- document.getElementById('tempDIV').innerHTML=newStr;
- }
- </script>
- </head>
- <body>
- <label for="txtBox">Enter a string : </label><input type="text" name="txtBox" id="txtBox">
- <button type="button" onclick="reverseString()">Reverse</button>
- <div id="tempDIV">
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement