Solved

Show / Hide Text Blocks Question

Posted on 2013-01-21
6
259 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

760 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