If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Sorting a table with a form

Hi,

I want to sort a table with a form in it in Javascript.

I used to pick the innerHTML of the rows for sorting tables. However, when I do that with an input element of a form I always get the original content of the input. Somehow innerHTML doesn't notice it when the user has changed the value of the input.

Does anyone know what is the logic behind this behavior. And how can I best work around it?

rnd_me,
This is a part of javascript where I feel absolutely ignorant. But the code worked. Thanks.

Just one problem: it only works once. If I make a change and sort it works. If I then make another change and sort again that second change is not implemented - no matter whether I called the formula a second time or not.

rnd_me,
This is a part of javascript where I feel absolutely ignorant. But the code worked. Thanks.

Just one problem: it only works once. If I make a change and sort it works. If I then make another change and sort again that second change is not implemented - no matter whether I called the formula a second time or not.

hmm, that's odd. i would guess that it's something to do with how the sort is coded, perhaps it's memorizing the "boot up" version of the table and resorting that each time.

if you post the code you have and we can figure it out im sure.

you might not even need to use innerHTML at all, you can simply grab the <tr> objects into an array, sort the array, and then loop though the array, appending each element of the sorted array of <tr>s to the <tbody>.
there are also some table sorter plugins for jquery that make it pretty simple to implement the functionality....

Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com