Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » Show hidden DIV from a link on another page?

Show hidden DIV from a link on another page?

Reply
  #1 (permalink)  
Old
New Member
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Show hidden DIV from a link on another page?

I have a page with a hidden DIV that is shown (or hidden) when you click on certain parts of the page. When the page loads, its default is hidden.
What I'd like to do is have the page load with the DIV shown when you click on a specific link from another page.
I've tried all the approaches I can think of, and don't really know where (or how) to begin looking for other ones...
I don't know if this possible or realistic, but if anyone can advise me, I'd appreciate it...
Reply With Quote
  #2 (permalink)  
Old
Wannabe Coder
 
Join Date: Jun 2004
Location: Boston, MA
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
You could pass a variable in a querystring that changes the "display" attribute to "visible." You can use PHP or your favorite server side language to accomplish this for you.
Reply With Quote
  #3 (permalink)  
Old
New Member
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I guess I need a little more to go on - I can pass a variable, but I can't get the figure out how to use it to change the display attribute.
Reply With Quote
  #4 (permalink)  
Old
Wannabe Coder
 
Join Date: Jun 2004
Location: Boston, MA
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Okay. on the page that displays the div you can include the following PHP code IN PLACE OF THE DIV that is normally hidden. Let's say your variable is called "display" and has the value "yes" or "no." We will write a script that will find out if a value for "display" is being passed in the URL. If it is, and if the value is "yes," it will add 'style="display:visible"' to the <div> tag in question. If no variables are being passed, or the value is not "yes," it won't.

Let's say the following is the normal HTML display, and that the class "hiddendiv" has some styling we want to maintain when we change display to :visible (e.g. margins, padding, etc):

Code:
<div class="hiddendiv">
 Content of div
</div>
Using some PHP, we can do this instead!
PHP Code:

<?


//if the url is mypage.php?display=yes, display the following html
if ((isset($_GET['display'])) && ($_GET['display'] == "yes")) {
     echo 
"<div class=\"hiddendiv\" style=\"display:block\">";
} else {
//otherwise display the normal div
     
echo  "<div class=\"hiddendiv\">";
}

?>

<!--now we're back in regular HTML-->
Content of div
</div>
Voila!

Edit: it occurs to me now that I should have asked whether you were using the attribute "display" (display:none) or "visibility" (visibility:invisible) to hide your hidden div. Either wait, the code will still work, though you may have to change "display:block" to "visibility:visible."

Last edited by kjmatthews; 05-06-05 at 04:08 PM.
Reply With Quote
  #5 (permalink)  
Old
Newbie Coder
 
Join Date: Jan 2005
Location: England
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Hi jbreaker,

There is no need to use PHP to accomplish what you are trying to achieve, although it will work that way.

All you need is a simple javascript function to show the layer when a link is clicked, we could also create a javascript function to hide the layer again.

Use the following code on your html page with the hidden layer.

Code:
<script language="javascript">
<!--
function show_div(item)
{
if (!item)
{
return;
}
 
item.style.display = "";
}
//-->
</script>
 
<div id="hidden" style="display:none;">Content</div>
 
<a href="javascript:show_div('hidden');">Show hidden layer</a>
This will show the hidden layer once the link has been clicked on. Hope this helps.

Kind Regards,
Wayne
Reply With Quote
  #6 (permalink)  
Old
Wannabe Coder
 
Join Date: Jun 2004
Location: Boston, MA
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
That function will work unless the user has disabled Javascript. The convenience of the PHP is that it is processed server side and can't be turned off by the user. Both are useful - it is your choice which one to use!
Reply With Quote
  #7 (permalink)  
Old
New Member
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for all the help! I've got it working now. I tried both options that were suggested - the javascript option wouldn't work for me across pages (I was able to show or hide the DIV from within the page itself, but not show it when clicking a link from a separate page) but it did give me an idea of another way to do it. The PHP worked fine as suggested.
Thanks again - I appreciate the responses!
Reply With Quote
  #8 (permalink)  
Old
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
I know you got your solution, but JS and php would be best. Use PHP to store a session, echo the session into JS, then JS will know to display or not. If you don't understand what I mean, I'll post examples later tonight.

I was building a forum and worked with popups divs.
Reply With Quote
  #9 (permalink)  
Old
New Member
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
does anyone know if this will work with divs on an included page?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Looking for simple "Password" script to access a hidden page. Nigel DV Script Requests 16 04-12-05 08:39 PM
Directing link to password protected page brb PHP 2 06-15-04 05:10 AM
How do I show a row per page? tbig ASP 2 02-12-04 05:19 PM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 02:18 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.