Solved

Show / Hide Text Blocks Question

Posted on 2013-01-21
6
263 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

825 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