How to hide/unhide web contents on the same web page?

Discussion in 'JavaScript' started by eppingwest, Jun 8, 2008.

  1. #1
    I am fasinated by hiding and unhiding web contents.

    Have seen some web site doing the above. When you check a checkbox called "More Info", more web contents will be displayed on the same page below the checkbox. When you uncheck "More Info" checkbox, previously displayed web contents will be hidden.

    New to web programming. Is there any sample javascript to do this?

    Thanks for your help in advance.
     
    eppingwest, Jun 8, 2008 IP
  2. eppingwest

    eppingwest Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    A good example is:
    http://www.consumer.philips.com/consumer/en/us/consumer/cc/_language_us/_productid_DVP3980_37_US_CONSUMER

    In the above web page, the little triangle "pointing right" hides web contents.

    Click on it will change the little triangle "pointing down" to unhide web contents.

    What is the javascript search name for this hide/unhide technique?

    Thanks.
     
    eppingwest, Jun 8, 2008 IP
  3. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #3
    add in "head" section of your page
    <script type="text/javascript">
    function hide(area){
    	var obj = document.getElementById(area);
    	if(obj.style.display=="none"){
    		obj.style.display=="block";
    	} else {
    		obj.style.display=="none";
    	}
    }
    </script>
    Code (markup):
    now, say you wanted to hide the divider named "content", just make this as a link

    <a href="#" onClick="hide("content");>toggle content area</a>

    when you click the link, it will open and close the area with the id "content"

    you can reuse this with any area, as long as you have the id set
     
    crath, Jun 8, 2008 IP
  4. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    what crat told is right, one small thing i would like to add is the calling of a js function from a link
    i.e this particular line

    when you click this you get a # appended to the link in the address bar, what you can do to avoid this is

    hope this helps too
     
    sharry, Jun 8, 2008 IP
  5. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Hi guys,

    Takings things one step further, would it be possible to have an "add" button that would add input fields vertically up to a maxim of, say, 10?

    This would be useful in forms where people need to enter varying amounts of values
     
    lanmonkey, Jun 19, 2008 IP
  6. QiSoftware

    QiSoftware Well-Known Member

    Messages:
    805
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    158
    #6
    "innerhtml" is another option for hiding and unhiding content.

    Q...
     
    QiSoftware, Jun 19, 2008 IP
  7. MoTioN MaN

    MoTioN MaN Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    well i use jquery but it land me in to problem when putting links in the content in internet explorer
     
    MoTioN MaN, Jun 23, 2008 IP