Show/Hide Row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mervyn
    New Member
    • Jun 2007
    • 3

    Show/Hide Row

    Hi There,

    I have recently started coding in ASP.NET (less than 2 weeks) and over the last day or 2 I've started using some Javascript. I have created a screen with a table and xx number of rows. All but one of the rows are shown immediately. I only want the row that is not shown to be shown (visible) based on some other data. The Javascript function runs and the row is displayed perfectly. The problem I am then faced with is that when I want to hide the row, a blank 'row' (or something) is left behind so there is the gap between the 2 visible questions. When the hidden row is made visible again, this row is shown above the blank row/line from the previous step. Doing this a few time leads to lots of blank rows/lines in the page.

    I know that there has to be a way to get this working properly but with my limited time working with this language, I'm afraid that I am hitting a brink wall here and its probably something that is stupid simple ... :)

    Your help will be greatly appreciated

    *************** *************** *************** *************** *************** *********
    function checkModelOptio ns(currentObjec t,currentDivObj ect)
    {
    var currentObject = $(currentObject );
    var urlData = $("urlData");
    var getContainer = currentObject.p arentNode.paren tNode.parentNod e;
    // Hide the ModelOptionsQue stion field immediately. Let the process below determine whether it should be shown
    $("modelOptions Question").styl e.display='none ';
    var optionContainer = $(currentDivObj ect);
    optionContainer .hide();
    if(currentObjec t.value != "")
    {
    var newUrl = "";
    newUrl = getLocation() + "xxxxxxxxxx/Table.aspx?type OfLookup=checkM odelOptions&" + getDecendantsVa lues(getContain er);
    newUrl += "&currentDivObj ect="+currentDi vObject;
    urlData.value = newUrl;
    loadXMLDoc(newU rl, "");
    }
    }
    *************** *************** *************** *************** *************** *********

    *************** *************** *************** *************** *************** *********
    case "checkModelOpti ons":
    enableModelOpti ons(jsonObject) ;
    break;
    *************** *************** *************** *************** *************** *********


    *************** *************** *************** *************** *************** *********
    function enableModelOpti ons(jsonObject)
    {
    $("modelOptions Question").styl e.display='bloc k';
    }
    *************** *************** *************** *************** *************** *********
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi,

    have a look at the following example the uses dom-scripting-methods instead of setting styles ... that will do the job:

    [HTML]
    <html>
    <head>
    <script>
    var hidden_row = null;
    var next_row = null;
    var parent_node = null;

    function hide_row(id) {
    var rows = document.getEle mentsByTagName( 'tr');

    for (var i = 0; i < rows.length; i++) {
    var row = rows[i];

    if (row.id == id) {
    hidden_row = row;
    next_row = rows[i + 1];
    break;
    }
    }

    parent_node = hidden_row.pare ntNode;

    parent_node.rem oveChild(hidden _row);
    }

    function show_hidden_row () {
    parent_node.ins ertBefore(hidde n_row, next_row);
    }
    </script>
    </head>
    <body>
    <table id="my_table">
    <tr id="row1">
    <td>test1</td>
    <td>test1</td>
    <td>test1</td>
    </tr>
    <tr id="row2">
    <td>test2</td>
    <td>test2</td>
    <td>test2</td>
    </tr>
    <tr id="row3">
    <td>test3</td>
    <td>test3</td>
    <td>test3</td>
    </tr>
    </table>

    <br/>

    <input type="button" value="Hide row2" onclick="hide_r ow('row2');"/>

    <input type="button" value="Show hidden row" onclick="show_h idden_row();"/>

    </body>
    </html>
    [/HTML]

    ask ... in case you need further explaination ... the script removes the row from the document-tree, but keeps a reference to it, and we may insert it back before the next sibling element (at the moment - this script only works if there is such a next sibling child-node - it relies on that! ;) in case the removed row is the last one, we have to adapt the script ;))

    kind regards ...

    Comment

    Working...