| a. Create a HTML page with a text box and a button. b. Take a string as input from user and count different types of characters in given string and print and also print the reverse of the string in same page. c. Validate for m fields for Empty - i. Above validation should happen on button click. ii. ON VALIDATION DISPLAY PROPER USER FRIENDLY MESSAGE TO USER. d. For example: “apple” would be a=1 p=2 l=1 and e=1 Reverse: apple -> elppa e. Display page content in the middle of the page with proper alignment. f. Try to design a good looking html page. g. You are only allowed to use HTML for design the page and JavaScript for scripting logic. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |
| <HTML> | |
| <HEAD> | |
| </HEAD> | |
| <script> | |
| function strReverse() | |
| { | |
| var input=document.getElementById('text1').value.trim(); | |
| var content=document.getElementById('stringt'); | |
| var newTable="<tr><td>"; | |
| var cha=new Array(); | |
| var reverse=[]; | |
| var leng=input.length-1; | |
| var stri=''; | |
| //reverse.length=input.length; | |
| var reg=/^[a-zA-Z._]+$/; | |
| if(!reg.test(input)) | |
| { | |
| alert("Please enter String"); | |
| return false; | |
| } | |
| cha.length=input.length; | |
| var count; | |
| for(var index=0;index<input.length;index++) | |
| { | |
| count=1; | |
| reverse[leng-index]=input[index]; | |
| for(var i=0;i<input.length;i++) | |
| { | |
| if(index!=i&&input[index]==input[i]) | |
| { | |
| count++; | |
| } | |
| } | |
| if(input[index]==input[index-1]){} | |
| else{ | |
| cha[index]=input[index]+'='+count; | |
| newTable=newTable+cha[index]+"</td></tr><tr><td>"; | |
| } | |
| } | |
| for(var c=0;c<leng+1;c++) | |
| { | |
| stri=stri+reverse[c]; | |
| } | |
| newTable=newTable+"<tr><td>"+stri+"</td></td></table>"; | |
| content.innerHTML=newTable; | |
| return true; | |
| } | |
| </script> | |
| <BODY><center> | |
| <form id='form' onsubmit='return strReverse()'> | |
| <div id='con' style="width:250px; background-color:green">Enter Your Name:<input type='text' name='str' id='text1' value=''><br> | |
| <input type='button' name='sbutton' id='strButton' value='submit' onclick='return strReverse()'><table id='stringt' style="width:250px; background-color:red; align:middle"></table> | |
| </div> | |
| </form></center> | |
| </BODY> | |
| </HTML> | |
Monday, July 15, 2013
Reverse String
Labels:
JavaScript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment