Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 06-25-2009, 06:30 AM   #1 (permalink)
Contributing Member
 
Foxtrck's Avatar
 
Join Date: 11-29-06
Location: Scotland, UK
Posts: 201
iTrader: 0 / 0%
Latest Blog:
None

Foxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebody
Send a message via MSN to Foxtrck
Nooby Javascript/PHP Hidden Div Problems

Hi, I'm trying to implement hidden content for a site in php.

PHP looks like this

PHP Code:
            for($i=0$i<$num_rows_publication$i++)
            {
                echo (
"<a href=\"javascript:unhide('content')\">" mysql_result($result_publication$i"pubName") . "</a>");
                                        
                
                
$query_files "SELECT * FROM files WHERE pubId = " 
                
mysql_result($result_publication$i"id") . " ORDER BY files.language";
                        
                        
$result_languages mysql_query($query_files) or die(mysql_error()); 
                        
                        
$num_rows_languages mysql_num_rows($result_languages);
                        
                        for(
$j=0$j<$num_rows_languages;$j++)
                        {                
                            echo(
"<div id='content' class='hidden'>");
                            echo(
"<table>");                        
                            echo(
"<tr><td class='language'><a href='" mysql_result($result_languages$j"file") . "'>" mysql_result($result_languages$j"language") . "</a></td></tr>");
                            echo(
"</table>");
                            echo(
"</div>");
                        }
                        
                echo(
"<hr/>");
            } 
So Ive got a heading and use that as a link to hide/show results from the database.

Javascript fot that is:

<script type="text/javascript">
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
item.className=(item.className=='hidden')?'unhidde n':'hidden';
}
}
</script>

and two classes hidden/unhidden.

It doesnt really work and im having big problems trying to implement this in the php areas.

Any suggestions?
__________________
http://www.dund.co.uk - DD1 Designs
Foxtrck is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-25-2009, 07:44 AM   #2 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,338
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
Instead of doing a class, why not just change the block's style.display attribute? You can change it from block (to show it) and none (to hide it).

This will also get rid of the space it takes up when visible.

So try this and see if it works:

Code:
<script type="text/javascript"> function unhide(divID) { var item = document.getElementById(divID); if (item) { item.style.display=(item.style.display=='block')?'none':'block'; } } </script>
PHP Code:
            for($i=0$i<$num_rows_publication$i++) 
            { 
                echo (
"<a href=\"javascript:unhide('content')\">" mysql_result($result_publication$i"pubName") . "</a>"); 
                                         
                 
                
$query_files "SELECT * FROM files WHERE pubId = " .  
                
mysql_result($result_publication$i"id") . " ORDER BY files.language"
                         
                        
$result_languages mysql_query($query_files) or die(mysql_error());  
                         
                        
$num_rows_languages mysql_num_rows($result_languages); 
                         
                        for(
$j=0$j<$num_rows_languages;$j++) 
                        {                 
                            echo(
"<div id='content'>"); 
                            echo(
"<table>");                         
                            echo(
"<tr><td class='language'><a href='" mysql_result($result_languages$j"file") . "'>" mysql_result($result_languages$j"language") . "</a></td></tr>"); 
                            echo(
"</table>"); 
                            echo(
"</div>"); 
                        } 
                         
                echo(
"<hr/>"); 
            } 
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is online now  
Add Post to del.icio.us
Reply With Quote
Old 06-25-2009, 08:05 AM   #3 (permalink)
Contributing Member
 
Foxtrck's Avatar
 
Join Date: 11-29-06
Location: Scotland, UK
Posts: 201
iTrader: 0 / 0%
Latest Blog:
None

Foxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebody
Send a message via MSN to Foxtrck
Hi thanks for the reply, i tried it and it doesnt seem to work just hide the link itself. Is there any way to set the block up of

PHP Code:
 for($j=0$j<$num_rows_languages;$j++)  
                        {                  
                            echo(
"<div id='content'>");  
                            echo(
"<table>");                          
                            echo(
"<tr><td class='language'><a href='" mysql_result($result_languages$j"file") . "'>" mysql_result($result_languages$j"language") . "</a></td></tr>");  
                            echo(
"</table>");  
                            echo(
"</div>");  
                        } 
to hidden, there will be many of these divs so cant be unique, and have an element outside the loop somewhere else to hide/show this?
__________________
http://www.dund.co.uk - DD1 Designs
Foxtrck is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-25-2009, 09:04 AM   #4 (permalink)
Meeow!
 
Costin Trifan's Avatar
 
Join Date: 04-13-07
Location: Romania
Posts: 3,235
iTrader: 0 / 0%
Latest Blog:
None

Costin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest order
if you want to hide/show the content then you should only hide/show the table tag and not the whole div, because this could help you add an event listener to that div so you can click on that div to toggle the table's visibility.

#1: search for a javascript function that will help you get a list of elements by class (if I remember correctly Dustin Diaz had published an article with a lot of useful functions)

#2: add the css class again to your div, this will help you select them

#3: create the toggle function

#4: or you can just use jquery or any other library you know how to use

__________________
...to be continued
Costin Trifan is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-25-2009, 09:42 AM   #5 (permalink)
Contributing Member
 
Foxtrck's Avatar
 
Join Date: 11-29-06
Location: Scotland, UK
Posts: 201
iTrader: 0 / 0%
Latest Blog:
None

Foxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebody
Send a message via MSN to Foxtrck
Do you havre any example of how i could implement it? It isnt quite working as i hoped.
__________________
http://www.dund.co.uk - DD1 Designs
Foxtrck is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-25-2009, 10:21 AM   #6 (permalink)
Contributing Member
 
Foxtrck's Avatar
 
Join Date: 11-29-06
Location: Scotland, UK
Posts: 201
iTrader: 0 / 0%
Latest Blog:
None

Foxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebody
Send a message via MSN to Foxtrck
Ok, so I used this php

PHP Code:
$result_publication mysql_query($query_publications) or die(mysql_error()); 
        
$num_rows_publication mysql_num_rows($result_publication);
        
header_search_results();

               for(
$i=0$i<$num_rows_publication$i++) 
            { 
                echo (
"<p>" mysql_result($result_publication$i"pubName") . "<a id='displayText' href='javascript:toggle();'> Show Available Languages</a></p>");
         
                 
                
$query_files "SELECT * FROM files WHERE pubId = " .  
                
mysql_result($result_publication$i"id") . " ORDER BY files.language"
                         
                        
$result_languages mysql_query($query_files) or die(mysql_error());  
                         
                        
$num_rows_languages mysql_num_rows($result_languages); 
                         echo(
"<div id='toggleText' style='display:none'>"); 
                        for(
$j=0$j<$num_rows_languages;$j++) 
                        {                 
                            
                            echo(
"<table>");                         
                            echo(
"<tr><td class='language'>
                            <a href='" 
mysql_result($result_languages$j"file") . "'>" mysql_result($result_languages$j"language") . "</a></td></tr>"); 
                            echo(
"</table>"); 
                             
                        } 
                         echo(
"</div>");
                echo(
"<hr/>"); 
            }  


    } 
with the following JS

Code:
<script language="javascript"> function toggle() { var ele = document.getElementById("toggleText"); var text = document.getElementById("displayText"); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "Show Available Languages"; } else { ele.style.display = "block"; text.innerHTML = "Hide Languages"; } } </script>
and the concept works with hidding divs


BUT the problem is, only the first result uses the hiding div. Is there a way to loop through every one? How would i change it to search by class?

Sorry, any suggestions... lack of sleep is making me this noobish again
__________________
http://www.dund.co.uk - DD1 Designs
Foxtrck is offline  
Add Post to del.icio.us
Reply With Quote
Old 06-25-2009, 02:18 PM   #7 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,338
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
This should work for you.

You just have to create a counter in the PHP and then add that count to the id.

I have updated the JavaScript slightly as well.

Code:
<script language="javascript"> function toggle(num) { var ele = document.getElementById("toggleText"+num); var text = document.getElementById("displayText"+num); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "Show Available Languages"; } else { ele.style.display = "block"; text.innerHTML = "Hide Languages"; } } </script>
PHP Code:
$result_publication mysql_query($query_publications) or die(mysql_error());  
        
$num_rows_publication mysql_num_rows($result_publication); 
        
header_search_results(); 
        
$count 0;

               for(
$i=0$i<$num_rows_publication$i++)  
            {  
                
$count++;
                echo (
"<p>" mysql_result($result_publication$i"pubName") . "<a id='displayText".$count."' href='javascript:toggle(".$count.");'> Show Available Languages</a></p>"); 
          
                  
                
$query_files "SELECT * FROM files WHERE pubId = " .   
                
mysql_result($result_publication$i"id") . " ORDER BY files.language";  
                          
                        
$result_languages mysql_query($query_files) or die(mysql_error());   
                          
                        
$num_rows_languages mysql_num_rows($result_languages);  
                         echo(
"<div id='toggleText".$count."' style='display:none'>");  
                        for(
$j=0$j<$num_rows_languages;$j++)  
                        {                  
                             
                            echo(
"<table>");                          
                            echo(
"<tr><td class='language'> 
                            <a href='" 
mysql_result($result_languages$j"file") . "'>" mysql_result($result_languages$j"language") . "</a></td></tr>");  
                            echo(
"</table>");  
                              
                        }  
                         echo(
"</div>"); 
                echo(
"<hr/>");  
            }   


    } 
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is online now  
Add Post to del.icio.us
Reply With Quote
Old 06-26-2009, 02:08 AM   #8 (permalink)
Contributing Member
 
Foxtrck's Avatar
 
Join Date: 11-29-06
Location: Scotland, UK
Posts: 201
iTrader: 0 / 0%
Latest Blog:
None

Foxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebodyFoxtrck is liked by somebody
Send a message via MSN to Foxtrck
worked a treat izzmo, many thanks - it was so obvious in hindsight.
__________________
http://www.dund.co.uk - DD1 Designs
Foxtrck is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
noob Having problems with javascript kevin316 Coding Forum 4 06-23-2009 09:18 PM
Encrypt Javascript - Secure Your Javascript Code ZunuZunu Services 7 03-09-2009 01:55 PM
Table and Javascript Problems in IE homebrewpcgaming Coding Forum 3 12-09-2008 03:25 PM
Hidden Div Tag drixie Google Forum 11 03-04-2008 07:47 AM
Count-up from a particular year + Javascript within Javascript? Help! Azam.biz Coding Forum 3 06-06-2005 07:47 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 04:14 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.