SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Hiding Row of Data

    Hey everyone,

    I've got a table where I want to "hide" a row of data (only for that pageview, so no cookies needed).

    I don't want to be able to unhide it, so that isn't needed either... Just need to hide it :|

    Any way to do this?

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Jeremy,

    If that TR has an id (let's say 'myRow') then perhaps...
    Code:
    window.onload = function() {
      if (document.getElementById) {
        var r = document.getElementById('myRow');
        if (r && r.style) {
          r.style.display = 'none';
        }
      }
    }

  3. #3
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Let me fire up terminal services and have a go
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not familiar with your situation. So I put that code in the onload listener just to emphasize that this can only be done after the page has loaded. It could also be in a function which gets called from your onload listener or from a click event, etc. Let me know if you need it for a different situation.
    Code:
    function hideMyRow() {
      if (document.getElementById) {
        var r = document.getElementById('myRow');
        if (r && r.style) {
          r.style.display = 'none';
        }
      }
    }

  5. #5
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hmm... Object Expected. I'd already rewritten it as a function anyways

    Here's the function:

    Code:
     function hideRows(c)
    {
     if (document.getElementById) 
     {
      var r = document.getElementById(c);
      if (r && r.style) 
      {
       r.style.display = 'none';
      }
      else
      {
       window.alert('nope');
      }
     }
    }
    And, the call (relevant):

    Code:
    <tr valign="top" id="TruckRow0">
    		   <td class="backform"><input type="checkbox" name="TruckId" value="14" class="check1"></td>
    		   <td class="Listing">&nbsp; <a href="#" onClick="hideRows('TruckRow0'); return false;"><b>[+]</b></a></td>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the following simple test and it worked without errors in Opera, Mozilla, and IE. I don't guess this is a page you can give a link to, eh?
    Code:
    <html>
    <head>
    <script>
    function hideRows(c)
    {
     if (document.getElementById) 
     {
      var r = document.getElementById(c);
      if (r && r.style) 
      {
       r.style.display = 'none';
      }
      else
      {
       window.alert('nope');
      }
     }
    }
    </script>
    </head>
    <body>
    
    <form>
    <table>
    <tr valign="top" id="TruckRow0">
       <td class="backform"><input type="checkbox" name="TruckId" value="14" class="check1"></td>
       <td class="Listing">&nbsp; <a href="#" onClick="hideRows('TruckRow0'); return false;"><b>[+]</b></a></td>
    <tr valign="top" id="TruckRow1">
       <td class="backform"><input type="checkbox" name="TruckId" value="14" class="check1"></td>
       <td class="Listing">&nbsp; <a href="#" onClick="hideRows('TruckRow1'); return false;"><b>[+]</b></a></td>
    <tr valign="top" id="TruckRow2">
       <td class="backform"><input type="checkbox" name="TruckId" value="14" class="check1"></td>
       <td class="Listing">&nbsp; <a href="#" onClick="hideRows('TruckRow2'); return false;"><b>[+]</b></a></td>
    </table>
    </form>
       
    </body>
    </html>
    Edit:

    i forgot to wrap the table in a form element, but it didn't change any results

  7. #7
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps the hideRows code is in a js file that has been cached so you're page might still be using the cached js file ?

  8. #8
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It was in a JS file, but I had local-page JS as well so I just put it in there and it worked fine.

    Thanks Mike, and good to meet you

    Congrats on mentordom
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  9. #9
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're very welcome, Jeremy.

    Have a great day.


Bookmarks

Posting Permissions

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