Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Sorting words and searching a string

    Hello there! I am working on a little project where I have a form that allows a user to input a sentence that will be sorted alphabetically when they click sort. The result should be displayed in the Output box at the bottom. Then They should be able to enter a string that will be search from the previous sentence entered and that search will display in the output as well. Then last they should be able to enter in a replacement string; however, I have not done much reading on that so I am completely clueless there. I thought I would start with the small stuff and last I would work on the replacement string. So I have the form done, but I seem to be struggling with the functions. I think I should use aname.sort to sort the words in ABC order. I am wondering if I am just completely off on how I am trying to do all of this. Any tips would be great, just to maybe point me in the right direction. Thank you so much!!

    Code:
    <?xml version = "1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns = "http://www.w3.org/1999/xhtml">
       <head>
          <title>Lab 2 Part B</title>
    
          <script type = "text/javascript">
             <!--
    
    	function outputArray( head, theArray) 
    	{ 
        		document.forms.myForm.results.value 
            	    = "\n" + head + theArray.join(" ") + "\n"; 
    	} 
    
    
    	function sortButton() 
    	{ 
      		var wordsSplit = document.forms.myForm.words.value.split(/ +/); 
        		var sorted     = wordsSplit.sort( 
                            function(a,b){ 
                                return (a.toLowerCase() > b.toLowerCase())? 1:-1 
                            } 
                    );
     
        		outputArray( 
            		"The words in your sentence are now in alphabetical order: ", 
            		sorted 
        		); 
    	} 
    
    
            function searchbuttonPressed() 
            {
               documednt.forms.myForm.results.value
    		= "\n" + document.writeln( "<br /> sentence.charCodeAt( searchstring ) + "</p>" );
    	}
    
    
       	function replacebuttonPressed() 
            {
              
    		
    
    	}
    
             // -->
          </script>
       </head>
    
       <body>
          <form name = "myForm" action = "">
             <p>Enter a sentence to work with:<br />
             <input name = "words" type = "text" size = "50">
             <input name = "sorted" type = "button" value = 
                   "Sort" onclick = "sortButton()" /></p>
    	
            <p>Enter a string to search for:<br /> 
             <input name = "searchstring" type = "text" size = "50"/>
             <input name = "search" type = "button" value = "Search"
                    onclick = "searchbutton()" /><br /></p>
    
            <p>Enter a replacement string to search for:<br /> 
             <input name = "replacestring" type = "text" size = "50"/>
             <input name = "replace" type = "button" value = "Replace"
                    onclick = "replacebutton()" /><br /></p>
               
             <p>Output:<br />
             <textarea name = "output" rows = "8" cols = "34">
             </textarea></p>  
    	
          </form>
       </body>
    </html>
    Last edited by zhah99; 10-24-2005 at 12:32 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You did excelent work, just keep going.
    rm -f /


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •