...

View Full Version : Sorting words and searching a string



zhah99
10-23-2005, 10:10 PM
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"
"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>

rm-f
10-24-2005, 01:55 PM
You did excelent work, just keep going.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum