Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: urgent

  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Thanked 0 Times in 0 Posts

    Angry urgent

    i have to sort the table in row wise,where i have images in first column,when i clicked first it shld sort in asending and if second time i clicked i have to sort desecding, it shld happen in row wise -please help-Urgent

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Thanked 0 Times in 0 Posts
    In the future a title other than urgent would be more appropriate. In fact, I almost skipped trying it because the post felt pushy.

    Anyway, I don't really like this answer but it sort of works. Turns out IE won't let you set innerHTML for rows in a table. So you have to recreate the entire table if you want to user innerHTML. Looks bad in FF too. But here it is anyway.


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <script type="text/javascript">
          var bSortAscending = false;
          function sortTest(a, b) {
            var y = a.getElementsByTagName("td")[1].innerHTML;
            var z = b.getElementsByTagName("td")[1].innerHTML;
            if (y == z) { return(0); }
            else if (y > z) { return((bSortAscending) ? 1 : -1); }
            else if (y < z) { return((bSortAscending) ? -1 : 1); }
          function doIt() {
            var tdiv = document.getElementById("tablediv");
            var t = document.getElementById("t");
            var arrayLike = t.getElementsByTagName("tr");
            var a = [];
            for (var i = 0; i < arrayLike.length; i++) {
              a[i] = arrayLike[i];
            var s = "<table id='t'>";
            for (var i = 0; i < a.length; i++) {
              s += "<tr>" + a[i].innerHTML + "</tr>";
            s += "</table>";
            tdiv.innerHTML = s;
            bSortAscending = !bSortAscending;
        <div id="tablediv">
          <table id="t">
            <tr><td><img src="images/mini_pizza.jpg" onclick="doIt();" /></td><td>Could it be?</td></tr>
            <tr><td><img src="images/mini_pizza.jpg" onclick="doIt();" /></td><td>Anyone here?</td></tr>
            <tr><td><img src="images/mini_pizza.jpg" onclick="doIt();" /></td><td>How do you know?</td></tr>
            <tr><td><img src="images/mini_pizza.jpg" onclick="doIt();" /></td><td>What time is it?</td></tr>


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts