Please help - Hide a table while show a table

Discussion in 'Javascript' started by michael941@gmail.com, Dec 10, 2006.

  1. Guest

    Hi,

    I have 2 tables in an html page. I have div them separately and id them
    as id1 and id2. I have a link there. What I need is click the link to
    hide one table and show the other and verse when click the link again.


    I tried many ways in javascript but failed. Could someone please help?

    Thanks a lot!
     
    , Dec 10, 2006
    #1
    1. Advertising

  2. VK Guest

    wrote:
    > Hi,
    >
    > I have 2 tables in an html page. I have div them separately and id them
    > as id1 and id2. I have a link there. What I need is click the link to
    > hide one table and show the other and verse when click the link again.
    >
    >
    > I tried many ways in javascript but failed. Could someone please help?


    Show your last try, we'll start from there.
     
    VK, Dec 10, 2006
    #2
    1. Advertising

  3. ASM Guest

    a écrit :
    > Hi,
    >
    > I have 2 tables in an html page. I have div them separately and id them
    > as id1 and id2. I have a link there. What I need is click the link to
    > hide one table and show the other and verse when click the link again.
    >
    >
    > I tried many ways in javascript but failed. Could someone please help?


    <button onclick="
    var id1 = document.getElementById('id1').style;
    var id2 = document.getElementById('id2').style;
    if(typeof(asm)=='undefined') {
    // 1st time you press button : hide div 2
    // asm is a pointer created at this moment
    // to avoid to hide 2nd div at each next pressure
    asm = true;
    id2.display = 'none';
    }
    else
    {
    id1.display = id1.display==''? 'none' : '';
    id2.display = id2.display==''? 'none' : '';
    };">hide / show </button>

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Dec 10, 2006
    #3
  4. Guest

    Hi, VK

    well, actually this javascript should be working in a jsp page finally,
    not html.

    I am guessing jsp should not be embbed into jsp?

    thanks

    On Dec 10, 1:53 pm, "VK" <> wrote:
    > wrote:
    > > Hi,

    >
    > > I have 2 tables in an html page. I have div them separately and id them
    > > as id1 and id2. I have a link there. What I need is click the link to
    > > hide one table and show the other and verse when click the link again.

    >
    > > I tried many ways in javascript but failed. Could someone please help?Show your last try, we'll start from there.
     
    , Dec 10, 2006
    #4
  5. Evertjan. Guest

    ASM wrote on 10 dec 2006 in comp.lang.javascript:

    > <button onclick="
    > var id1 = document.getElementById('id1').style;
    > var id2 = document.getElementById('id2').style;
    > if(typeof(asm)=='undefined') {
    > // 1st time you press button : hide div 2
    > // asm is a pointer created at this moment
    > // to avoid to hide 2nd div at each next pressure
    > asm = true;
    > id2.display = 'none';
    > }
    > else
    > {
    > id1.display = id1.display==''? 'none' : '';
    > id2.display = id2.display==''? 'none' : '';
    > };">hide / show </button>



    A global variable remembering the status is not even neccessary:

    <script type='text/javascript'>
    function swap(button,a,b) {
    var x = document.getElementById(a).style;
    var y = document.getElementById(b).style;
    var swapper = y.display == 'none';
    x.display = swapper ? 'none' : '';
    y.display = swapper ? '' : 'none';
    button.innerHTML = swapper ?
    'hide '+b+' / show '+a :
    'hide '+a+' / show '+b;
    }
    </script>

    <button onclick="swap(this,'id1','id2')">
    hide div id2</button>
    <br><br>
    <div id='id1'>This is id1</div>
    <div id='id2'>This is id2</div>
    <br><br>
    <button onclick="swap(this,'id3','id4')">
    hide div id4</button>
    <br><br>
    <div id='id3'>This is id3</div>
    <div id='id4'>This is id4</div>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 10, 2006
    #5
  6. Guest

    Thanks, Evertjan,

    Your way works sooooooooooooo wellllll~!

    Cheers

    On Dec 10, 3:37 pm, "Evertjan." <> wrote:
    > ASM wrote on 10 dec 2006 in comp.lang.javascript:
    >
    > > <button onclick="
    > > var id1 = document.getElementById('id1').style;
    > > var id2 = document.getElementById('id2').style;
    > > if(typeof(asm)=='undefined') {
    > > // 1st time you press button : hide div 2
    > > // asm is a pointer created at this moment
    > > // to avoid to hide 2nd div at each next pressure
    > > asm = true;
    > > id2.display = 'none';
    > > }
    > > else
    > > {
    > > id1.display = id1.display==''? 'none' : '';
    > > id2.display = id2.display==''? 'none' : '';
    > > };">hide / show </button>A global variable remembering the status is not even neccessary:

    >
    > <script type='text/javascript'>
    > function swap(button,a,b) {
    > var x = document.getElementById(a).style;
    > var y = document.getElementById(b).style;
    > var swapper = y.display == 'none';
    > x.display = swapper ? 'none' : '';
    > y.display = swapper ? '' : 'none';
    > button.innerHTML = swapper ?
    > 'hide '+b+' / show '+a :
    > 'hide '+a+' / show '+b;}</script>
    >
    > <button onclick="swap(this,'id1','id2')">
    > hide div id2</button>
    > <br><br>
    > <div id='id1'>This is id1</div>
    > <div id='id2'>This is id2</div>
    > <br><br>
    > <button onclick="swap(this,'id3','id4')">
    > hide div id4</button>
    > <br><br>
    > <div id='id3'>This is id3</div>
    > <div id='id4'>This is id4</div>
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    , Dec 10, 2006
    #6
  7. ASM Guest

    Evertjan. a écrit :
    > ASM wrote on 10 dec 2006 in comp.lang.javascript:


    Hi,

    > A global variable remembering the status is not even neccessary:


    Not too bad :)


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Dec 10, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zambien
    Replies:
    2
    Views:
    172
    Dr John Stockton
    Oct 2, 2004
  2. Ryh
    Replies:
    3
    Views:
    372
  3. Replies:
    4
    Views:
    254
  4. Erik Lautier

    Hide/Show Issue, Please Help

    Erik Lautier, Nov 10, 2006, in forum: Javascript
    Replies:
    1
    Views:
    71
    Randy Webb
    Nov 10, 2006
  5. ll
    Replies:
    2
    Views:
    651
    Thomas 'PointedEars' Lahn
    May 1, 2008
Loading...

Share This Page