Hello and welcome to our community! Is this your first visit?
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
    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!!

    <?xml version = "1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    <html xmlns = "http://www.w3.org/1999/xhtml">
          <title>Lab 2 Part B</title>
          <script type = "text/javascript">
    	function outputArray( head, theArray) 
            	    = "\n" + head + theArray.join(" ") + "\n"; 
    	function sortButton() 
      		var wordsSplit = document.forms.myForm.words.value.split(/ +/); 
        		var sorted     = wordsSplit.sort( 
                                return (a.toLowerCase() > b.toLowerCase())? 1:-1 
            		"The words in your sentence are now in alphabetical order: ", 
            function searchbuttonPressed() 
    		= "\n" + document.writeln( "<br /> sentence.charCodeAt( searchstring ) + "</p>" );
       	function replacebuttonPressed() 
             // -->
          <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">
    Last edited by zhah99; 10-24-2005 at 12:32 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Toronto, ON, Canada
    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