2 dimensional array - sorting mechanism

T

Totti

Hi everyone,
I am a newbie to javascript learning it for 2 months now, i am trying
to make a sorter who will read english words from the one textbox or
datafile and store them in a 2 dimensional array, so in other words,
howerever the words are set, horizontally the one following th eother
or the one under the other i want it to work, i tried some code but i
am having problems it only work when the text entered is horizontal
like the one word following the other when i try to enter a second
word after pressing ENTER, i dont get any result,

here is my code:

<html>
<head>
<title>Numbers and Words Sorter</title>
</head>
<body>
<td><b>Sorting Machine</b></td><p>

<script type="text/javascript">

function sortalpha(x,y)
{
return(x-y)
}

function sortvalues(param)
{
var inputvalues =
document.Form.textInput.value.toUpperCase().split(" ")

if (param==0)

inputvalues.sort()

else

inputvalues.sort(sortalpha)

for (i=0; i < inputvalues.length-1; i++)

document.Form.textOutput.value = document.Form.textOutput.value
+inputvalues + " "

document.Form.textOutput.value += inputvalues[inputvalues.length-1]

}
</script>

<form name="Form">

<textarea rows="10" name="textInput" cols="30" wrap="virtual">
</textarea>
<textarea rows="10" name="textOutput" cols="30" wrap="virtual">
</textarea>
<p>
<input type = "button" value="Sort Letters" name="Button"
onClick="sortvalues(0)">
<br>
<input type = "button" value="Sort Numbers" name="Button"
onClick="sortvalues(1)">
<br>
<input type = file name ="file" size =15>
<br>
<input type = "button" value="print" name="Button"
onClick="print(document.Form.textOutput.value)">
<br>
<input type = "reset" value="Reset" name="Button">
</form>
</body>
</html>


===============================================================

this code works in some cases but in others it doesnt for example in
the case of parenthesis, the parenthesis do not go before the letters
eventhough their ASCII is < , and it generates empty spaces in the
output which i can not explain, i know it is something wrong in my
code but i need your help please pointing out the problem.

I want to make this program work perfect, and i want to add more
things to it, but for the time being this is the obvious problem i am
infront,

Thanks in advance for any help!
 
T

Thomas 'PointedEars' Lahn

Totti said:
I am a newbie to javascript learning it for 2 months now, [...]

You need to study a lot more. Learn to write whole sentences,
Valid markup, legible code, working code; in that order.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top