onClick makes text appear

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Hoek

    #1

    onClick makes text appear

    Hi,

    I try to create the following:

    2 buttons next to each other, on a webpage
    button 1 makes (onClick) text 1 appear just beneath the button
    button 2 makes (onClick) text 2 appear just beneath the button

    in each of the texts at the end there's a third button to make the text
    dissappear again

    IS THIS POSSIBLE?
    HOW?

    Love to hear from you.

    Frank H.



  • Lasse Reichstein Nielsen

    #2
    Re: onClick makes text appear

    "Frank Hoek" <frankma@planet .nl> writes:
    [color=blue]
    > 2 buttons next to each other, on a webpage
    > button 1 makes (onClick) text 1 appear just beneath the button
    > button 2 makes (onClick) text 2 appear just beneath the button
    >
    > in each of the texts at the end there's a third button to make the text
    > dissappear again
    >
    > IS THIS POSSIBLE?[/color]

    Yes.
    Your caps lock key is stuck :)
    [color=blue]
    > HOW?[/color]
    ---
    <input type="button" value="Button 1"
    onclick="docume nt.getElementBy Id('text1').sty le.visibility=' visible';">
    <div id="text1" style="visibili ty:hidden;">
    This text is revealed by button 1 and hidden by button 3.
    <input type="button" value="Button 3"
    onclick="docume nt.getElementBy Id('text1').sty le.visibility = 'hidden';">
    </div>
    <input type="button" value="Button 2"
    onclick="docume nt.getElementBy Id('text2').sty le.visibility=' visible';">
    <div id="text2" style="visibili ty:hidden;">
    This text is revealed by button 2 and hidden by button 4.
    <input type="button" value="Button 3"
    onclick="docume nt.getElementBy Id('text2').sty le.visibility = 'hidden';">
    </div>
    ---

    I use the CSS property "visibility " to hide and show the texts.
    That means that they still take up room on the page, you just can't see
    the contents.
    You can use "display" instead, setting it to "none" to hide or "block"
    to show the text. The advantage of "visibility " is that it works in
    more browsers, e.g. Opera 6 (and Netscape 4, but getElementById doesn't
    work there).

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Evertjan.

      #3
      Re: onClick makes text appear

      Frank Hoek wrote on 21 nov 2003 in comp.lang.javas cript:
      [color=blue]
      > Hi,
      >
      > I try to create the following:
      >
      > 2 buttons next to each other, on a webpage
      > button 1 makes (onClick) text 1 appear just beneath the button
      > button 2 makes (onClick) text 2 appear just beneath the button
      >
      > in each of the texts at the end there's a third button to make the text
      > dissappear again
      >
      > IS THIS POSSIBLE?
      > HOW?[/color]

      <script>
      function sw(y,x){
      t=document.getE lementById(x).s tyle
      t.visibility=(y =='on')?'visibl e':'hidden'
      }
      </script>

      <style>
      #div1,#div2 {visibility:hid den;}
      </style>


      <button onclick=sw('on' ,'div1')>Show</button>
      <div id=div1>
      Text of div1
      <button onclick=sw('off ','div1')>Hide</button>
      </div>

      <button onclick=sw('on' ,'div2')>Show</button>
      <div id=div2>
      Text of div2
      <button onclick=sw('off ','div2')>Hide</button>
      </div>



      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Fabian

        #4
        Re: onClick makes text appear

        Frank Hoek hu kiteb:
        [color=blue]
        > Hi,
        >
        > I try to create the following:
        >
        > 2 buttons next to each other, on a webpage
        > button 1 makes (onClick) text 1 appear just beneath the button
        > button 2 makes (onClick) text 2 appear just beneath the button
        >
        > in each of the texts at the end there's a third button to make the
        > text dissappear again
        >
        > IS THIS POSSIBLE?
        > HOW?[/color]

        This is almost exactly how the menu system in my web pages functions.
        Click my sig to find out how - I'm a hit-whore :-)


        --
        --
        Fabian
        Visit my website often and for long periods!
        Penasaran slot depo 10k di AGAM69? Simak pengalaman main Mahjong Ways dan buy spin modal receh yang berakhir manis. Daftar dan buktikan sendiri.


        Comment

        • Frank Hoek

          #5
          Re: onClick makes text appear

          Problem solved.
          Thanks, guys!

          F.


          Comment

          Working...