Forum Moderators: open

Message Too Old, No Replies

Sorting by java script

i want to sort my page content by taking user input

         

mausam

11:18 am on May 17, 2002 (gmt 0)



Hi,
I have an HTMl file.

<HTML>
<BODY BGCOLOR="#FFFFFF">
<form>
<INPUT TYPE = text Name = "someName" SIZE=20>
<BR/>
Aminur
<BR/>
Rashid<BR/>
Thomas<BR/>
Mary<BR/>John<BR/>
Chirs<BR/>
D'souza<BR/>
Imran
</BODY>
</form>
</HTML>

I want to use a java script code so that if user enters any character in the textField .i.e Input text the name should get sorted by that character or the name starting with that character should get higlighted.
N e way to do it
Help me out :)

Stue

11:46 am on May 17, 2002 (gmt 0)

10+ Year Member



At first, I see you are about to write the markup code in XHTML as youre using <BR/> instead of <BR>. You would have to apply that slash to the <INPUT> tag as well. Just for your information :).

I assume that by "sorted by that character" you mean
a) you can only enter ONE character into the input field
b) only those names that START with the character are displayed

Well, i dont have a certain idea yet, but what you would have to make javascript do for you is the following.
All the names must be accessable for javascript in some kind of an array or such (name[0] = "Thomas").
When you submit the input the script will check every name in the array for its beginning letter and will write those, to which the character applies, into a new array (selected[0] = "Thomas"). Then, just sort that array via javascript (selected.sort()).
Now, you will have to write the names one after the other into a contender like a div (preferably) by using the .innerHTML element, seperated by <BR> (or <BR/> ) for example.

Thats how i would approach this. But i didnt understand the highlight thing, yet.