473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Show 1 out of 3 iFrames by clicking corresponding button (3 iFrames, 3 buttons)

I have 3 button-images in one page, such that when you press 1, it should show the iFrame related to it, and hide the others. I just started learning about webdev, and I've browsed online, but i can't seem to make it work. :o

Here's my code:

Expand|Select|Wrap|Line Numbers
  1.     <div id="tabs">  
  2.     <div id="overview">  
  3.     <a href="#wrapper">Overviews</a>  
  4.     </div>  
  5.     <div id="gallery">  
  6.     <a href="#wrapper2">Gallery</a>  
  7.     </div>  
  8.     </span>  
  9.     <div id="reviews">  
  10.     <a href="#wrapper3">Reviews</a>  
  11.     </div>  
  12.     </div>
Each wrapper# is the id of a div that contains the iFrame. The divs contained in the tabs div above are button-images.

How can I show 1 frame 1st, then when the other button-image is clicked, that iFrame will hide, and the iFrame corresponding to the button clicked will be the only 1 showing?

Thank you so much in advance!! :)

P.S. you can check out my website www.giroapps.com to get a better picture of what i'm trying to achieve. :)
Jan 16 '10 #1

✓ answered by Atli

Hey.

I would suggest one of two methods, to swap out the contents of an element.

#1 A single <iframe> who's contents are changes by <a> tags.
For example:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <head>
  3.     <title>Test</title>
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. </head>
  6. <body>
  7.     <div>
  8.         <div>
  9.             <a target="searchFrame" href="page1.html">First</a> |
  10.             <a target="searchFrame" href="page2.html">Second</a> |
  11.             <a target="searchFrame" href="page3.html">Third</a>
  12.         </div>
  13.         <hr>
  14.         <iframe name="searchFrame" width="550" height="400"></iframe>
  15.     </div>
  16. </body>
  17. </html>
By specifying the target attribute of the <a> tag, it will open the link in the targeted <iframe>, rather than the browser window itself.

#2 Swapping the contents of a <div> using AJAX.
This is essentially the 2.0 version of the first suggestion. It uses more modern techniques, which give you more control over what happens, and give you a lot more options as to how the data is handled.

However, it requires that JavaScript is enabled, and it requires a little more code.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <head>
  3.     <title>Test</title>
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5.     <script type="text/javascript">
  6.     function swapContent(targetID, url) {
  7.         var target = document.getElementById(targetID);
  8.  
  9.         var ajax = new XMLHttpRequest();
  10.         ajax.open('GET', url, true);
  11.         ajax.onreadystatechange = function() {
  12.             if(ajax.readyState == 4) {
  13.                 target.innerHTML = ajax.responseText;
  14.             }
  15.         }
  16.         ajax.send(null);
  17.     }
  18.     </script>
  19. </head>
  20. <body>
  21.     <div>
  22.         <div>
  23.             <a href="javascript: void();" onclick="swapContent('searchDiv', 'page1.html');">First</a> |
  24.             <a href="javascript: void();" onclick="swapContent('searchDiv', 'page2.html');">Second</a> |
  25.             <a href="javascript: void();" onclick="swapContent('searchDiv', 'page3.html');">Third</a>
  26.         </div>
  27.         <hr>
  28.         <div id="searchDiv" style="width: 550px; height: 400px; overflow: scroll;">Please select one...</div>
  29.     </div>
  30. </body>
  31. </html>
  32.  

3 3754
Atli
5,058 Expert 4TB
Hey.

I would suggest one of two methods, to swap out the contents of an element.

#1 A single <iframe> who's contents are changes by <a> tags.
For example:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <head>
  3.     <title>Test</title>
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. </head>
  6. <body>
  7.     <div>
  8.         <div>
  9.             <a target="searchFrame" href="page1.html">First</a> |
  10.             <a target="searchFrame" href="page2.html">Second</a> |
  11.             <a target="searchFrame" href="page3.html">Third</a>
  12.         </div>
  13.         <hr>
  14.         <iframe name="searchFrame" width="550" height="400"></iframe>
  15.     </div>
  16. </body>
  17. </html>
By specifying the target attribute of the <a> tag, it will open the link in the targeted <iframe>, rather than the browser window itself.

#2 Swapping the contents of a <div> using AJAX.
This is essentially the 2.0 version of the first suggestion. It uses more modern techniques, which give you more control over what happens, and give you a lot more options as to how the data is handled.

However, it requires that JavaScript is enabled, and it requires a little more code.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <head>
  3.     <title>Test</title>
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5.     <script type="text/javascript">
  6.     function swapContent(targetID, url) {
  7.         var target = document.getElementById(targetID);
  8.  
  9.         var ajax = new XMLHttpRequest();
  10.         ajax.open('GET', url, true);
  11.         ajax.onreadystatechange = function() {
  12.             if(ajax.readyState == 4) {
  13.                 target.innerHTML = ajax.responseText;
  14.             }
  15.         }
  16.         ajax.send(null);
  17.     }
  18.     </script>
  19. </head>
  20. <body>
  21.     <div>
  22.         <div>
  23.             <a href="javascript: void();" onclick="swapContent('searchDiv', 'page1.html');">First</a> |
  24.             <a href="javascript: void();" onclick="swapContent('searchDiv', 'page2.html');">Second</a> |
  25.             <a href="javascript: void();" onclick="swapContent('searchDiv', 'page3.html');">Third</a>
  26.         </div>
  27.         <hr>
  28.         <div id="searchDiv" style="width: 550px; height: 400px; overflow: scroll;">Please select one...</div>
  29.     </div>
  30. </body>
  31. </html>
  32.  
Jan 18 '10 #2
your 1st solution worked!! :) but i still have to click the 1st tab before it loads the frame. how do i set the 1st tab to be chosen as default upon loading the page? :) thanks so much again!! :)
Jan 19 '10 #3
Atli
5,058 Expert 4TB
You can set the src attribute of the tag.

Expand|Select|Wrap|Line Numbers
  1. <iframe src="page1.html" ... >
P.S.
You can use that page I linked: w3schools.com, to check out how various elements work.
Jan 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Pieter Linden | last post by:
In Access 2000, I would have sworn I could see the controltiptext of a button without clicking on it. Can this still be done in AccessXP? If so, does someone have a code snippet showing how to do...
0
by: gaurav | last post by:
hi, I have a problem, How do i use TextChanged Event by clicking on Button. When i changed the text in text box and moving the focus from there then it is working but i have one calender popup...
2
by: gaurav | last post by:
hi, I have a problem, How do i use TextChanged Event by clicking on Button. When i changed the text in text box and moving the focus from there then it is working but i have one calender popup...
3
by: anand basha | last post by:
Hi, How to set values dynamicaly to dropdown listbox while clicking the button *** Sent via Developersdex http://www.developersdex.com ***
1
by: Ian Davies | last post by:
I am trying to move some text by clicking a button. When clicked the button runs the java script and this will then take the value in the text field and add 10 to it to create a new value, this is...
0
by: denvercr | last post by:
Hi Guys, If you can help me on this problem, how can i possibly call or run a powerpoint slideshow when clicking a button in an asp.net page? Thank you guys for your assistance..
10
by: mjahabarsadiq | last post by:
I would like to reload the page when it is redirected by the browser's Back or Forward button. I tried the following but it does not works. <link rel="prev" href="url"> <link rel="next"...
1
oranoos3000
by: oranoos3000 | last post by:
hi i,m writing a script for chat room i,d like to with clicking close button of browser user is exited from site meaning of this say is with clicking close button all of session variable is...
11
by: bala venkata siva ram kum | last post by:
I am facing a problem while clicking edit button of a gridview.after clicking edit button it is displaying empty textboxes. I need old values in that textboxes. Here i used 3-tier architecture....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.