Solved

Show / Hide Text Blocks Question

Posted on 2013-01-21
6
261 Views
Last Modified: 2013-01-22
Hi everyone,

I have some text on the page arranged liked this:

Title
Block 1 of text


Title
Block 2 of text

Would someone be able to help me so that if you click on the title it shows the block of text underneath and if you click on the title again it hides the text?

Thanks,

D
0
Comment
Question by:TLN_CANADA
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 38804206
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 38804233
try this

<html>
<head>
<title>my javascript show script</title>

<script type="text/javascript">
      function showStuff(id) {
      if (document.getElementById(id).style.display == 'block')
            document.getElementById(id).style.display = 'none';
            else
            document.getElementById(id).style.display = 'block'
      }
</script>

</head>
<body>

<p><a href="#" onclick="showStuff('answer1'); return false;">What price are your apples?</a><br>
<span id="answer1" style="display: none;">Our apples are 30 pence each. If you buy 10 or more we can sell them at a discounted bulk rate of 25 pence each.</span></p>

</body>
</html>
0
 

Author Comment

by:TLN_CANADA
ID: 38804275
Thank you pratima, it works except when I put php in the output it does not hide on the page load:

<p><a href="#" onclick="showStuff('answer1'); return false;">Today:</a><br>
<span id="answer1" style="display: none;"><?php foreach ($res as $k => $v) {
    echo str_replace('__', $v, $html[$k]) . PHP_EOL;
} ?>
</span></p>

Open in new window


Do I need to put something around the php for it to work?

Thanks,

D
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38804320
try puttin simple PHP text only rather than Loop
0
 

Author Comment

by:TLN_CANADA
ID: 38804327
Tell you tell me how to print the results of the loop into another variable and then print this variable here as I need the results of the loop in this block. Thanks for your help :)
0
 

Author Comment

by:TLN_CANADA
ID: 38808682
Thanks, I have this figured out now.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now