T
Totti
Hi all,
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 tex area or
data file and show the result in the 2nd text area, in other words,
howerever the words are set, horizontally the one following the other
or vertically, 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,
Example : say i have " to be or not to be,this is the question" i want
to have "BE BE,THIS IS NOT OR QUESTION THE TO TO" this seems correct
but actually it is not because the "," ascii is less than the letters
so it should go first, and the second problem is that there are spaces
in the output that i can not understand where they are coming from and
i dont know how to deal with them.
the second problem is that if i enter:
to
be
or
not
to
be,
this
is
the
question
pressing enter after each word the script doesnt seem to work at all
it just copy the input to the output, instead i want to make it do the
following :
",
BE
BE
THIS
IS
NOT
OR
QUESTION
THE
TO
TO
"
here is my code:
<html>
<head>
<title>Numbers and Words Sorter</title>
</head>
<body>
<b>Sorting Machine</b><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!
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 tex area or
data file and show the result in the 2nd text area, in other words,
howerever the words are set, horizontally the one following the other
or vertically, 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,
Example : say i have " to be or not to be,this is the question" i want
to have "BE BE,THIS IS NOT OR QUESTION THE TO TO" this seems correct
but actually it is not because the "," ascii is less than the letters
so it should go first, and the second problem is that there are spaces
in the output that i can not understand where they are coming from and
i dont know how to deal with them.
the second problem is that if i enter:
to
be
or
not
to
be,
this
is
the
question
pressing enter after each word the script doesnt seem to work at all
it just copy the input to the output, instead i want to make it do the
following :
",
BE
BE
THIS
IS
NOT
OR
QUESTION
THE
TO
TO
"
here is my code:
<html>
<head>
<title>Numbers and Words Sorter</title>
</head>
<body>
<b>Sorting Machine</b><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!