SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting tablerows from whitin a div

    Hi guys, I have another problem.

    Say that i have a div with id "testdiv" and that div contains a table with id "testresults". The table rows have servral classes, for example one rows class is "testcase-ok".

    Now here comes the tricky part, I have another table "overviewtestresults" inside another <div> with id "overview".

    And I want to pick out all the table rows in the table "testresults" with id testcase-ok and put them in the "overviewtestresults table.

    I have the javascript to hide and show diffrent rows, but how do I acomplish this other task?

    Thanks for an amazing forum

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just want to add that the div "testdiv" contains much more than testresults, so i don't want to show that div.

  3. #3
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    So, #testdiv is invisible?

    Could you use a getElementsByClassName("testcase-ok") to grab your testcase rows?
    (note you'd have to either use a pre-made getElementsByClassName or write one yourself, it doesn't exist in basic Javascript yet)

    with id testcase-ok
    You meant class, right?

    Then you could use any number of ways to add those tr's to the other table... you could loop through them (since after gettingElementsByClassName you'll have a nodeList, a group of elements) and appendChild to the table (or the tbody if your table explicitly has one). Or, I recently learned, you can createDocumentFragment, stuff the tr's into that, and do one appendChild to the other table.

    I have the javascript to hide and show diffrent rows, but how do I acomplish this other task?
    I'm going to ask that a mod move this thread over to Javascript, because I believe that yes, you'll need to use Javascript for this if you want this to happen when a user Does Something (but, you didn't say). However if you want this done before a page even loads, you're either asking a question of how to copy-paste in a text editor (I don't think you are) or how to do this with a back-end language like PHP (I'm also thinking you don't mean this either).

    If you want these rows to move from an invisible table over to another table when the user does something via the browser then go ahead and hit the little flag under your name and in the message box, as a moderator to move this thread over to the correct section. I know this isn't an HTML/CSS question, you can't do this without scripting that I know of.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    I'm going to ask that a mod move this thread over to Javascript
    Done
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes i meant class "test-ok" my bad.

    I already have created the getElementsByClassName("testcase-ok") javascript so that already works fine.

    Code:
    function hideDisplay(textstring, tag) {
    var myclass1 = new RegExp('\\b'+textstring+'\\b');
    //Populate the array with all the page tags
    var allPageTags=document.getElementsByTagName("*");
    //Cycle through the tags using a for loop
    for (i=0; i<allPageTags.length; i++) {
    //Pick out the tags with our class name
    if (myclass1.test(allPageTags[i].className)) {
    if(tag=='hide'){
    allPageTags[i].style.display='none';
    }
    else{
    allPageTags[i].style.display='';
    }
    }
    }
    }

    I just wanted to take a row having the class"test-ok" from one table and show it in another table without having to write two exactly same tables contaning exactly the same information. But i will search the appendChild function and see if i can find a sollution using that.

    Thanks ur very helpful as always

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and yes testdiv is display.'none';

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here a link that describes the problem


    http://img41.imageshack.us/img41/7233/problemqh.jpg


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
  •