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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX call and timing of table sorting script 1

Status
Not open for further replies.

BigRed1212

Technical User
Mar 11, 2008
550
0
0
US
Hey.

I'm sure this is a timing thing, but I'm looking for a way to make it work.

I use this javascript to make tables sortable.

Easy. Highly recommended.

I have a page that presents the users a form with some selects, then executes an onChange function that makes an AJAX call to an ASP page that collects the user input and dumps some tabular output to the bottom half of the page. Works just fine.

What I want to do is have the tabular output returned by the ASP page be sortable using the above script.

I think there are timing issues.

If I put the script on the initial page and create a nondynamic table on the page from the get go, it is sortable and everything works fine. The returned table in the above example, however, is not sortable. This makes sense as the returned table doesn't exist when the original page is loaded.

I tried putting the sortable script in the ASP page returning the data thinking that would fire it but no joy.

Thoughts? How could I make a client side script see the ASP generated AJAX returned stuff? It isn't reloading so onLoad won't work.

The only other thing I can think of is maybe there is someway to have the return output write into the original DOM nodes of the original document, but that is deep water for me and I don't really know what I am talking about there.

I might be able to do something like write the column headings as anchors that make their own AJAX calls to sort the data, but that might get deep real quick as well and I'm not sure I want to do that in any event.

Ideas?

PS- I posted this almost word for word on another forum and got no responses, so I'm hoping Tek-Tips will impress me yet again.
 
Giving the table an id and changing it's class after drawing it seemed to do the trick.

In the returned asp:
<table id='foo' class='sortable' border='0'>


In the js:
function stateChanged()

{if (xmlhttp.readyState==4)
{document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
sorttable.makeSortable(document.getElementById('foo'));
}
if (xmlhttp.readyState==2)
{document.getElementById("txtHint").innerHTML="Loading";}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top