Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

words sorting 1

Status
Not open for further replies.

canobe

Technical User
Jan 18, 2003
86
MY
say that an user key-in "hello how are you" in a text box, whenever the user click on a button, the text should be display in ascending order like "are hello how you". how can i do this in javascript? thanks in advance
 
split the string by " " (space)

sort the array by sort() function

then return the sort value

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811

onpnt2.gif
 
good , easy and efficient way of doing it.
A star for the idea.

I was thinking of implementing a Hash or some other sort of algorithms.

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
 
[smile]

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811

onpnt2.gif
 
the tutorial is declare the text in the variable. now i must prompt user with text box, and i cant know how many text the user will input, might be 10 or 20. so how can i split the text in the textbox?
 
the tutorial is declare the text in the variable. now i must prompt user with text box, and i cant know how many text the user will input, might be 10 or 20. so how can i split the text in the textbox? anyway the link help me lots, thank you.
 
its better for me to paste the code here

<html>
<head>
<title>Sorting</title>
</head>
<body>
<h1>Sorting</h1>
<input type=&quot;textbox&quot; name=txt1 size=30>
<input type=&quot;button&quot; name=btn1 value=&quot;Sort&quot;>

<script language=&quot;JavaScript&quot;>
myString = new String(txt1)
splitString = myString.split(&quot; &quot;)
for (i=0; i < myString.length; ++i)
displayLine(spliString)

sort = splitString.sort()
document.write(&quot;<p>&quot; + sort)
</script>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top