Hello,
I have copied this code but I do not really understand what this code is about. . :?: When I put this into my code to expand certain terms, it shows result but it just shows the last record in my table..not taking the variable I posted. Can anyone explain this to me? thank you.

<script>
function expand(sec)
{
     thisSec = eval('e' + sec);
     if (thisSec != null){
          if (thisSec.length){
               if (thisSec[0].style.display != 'none'){
                    for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'none'}
               }
               else{
                    for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'inline'}
               }
          }
          else{
                         if (thisSec.style.display != 'none')     {thisSec.style.display = 'none'}
               else{thisSec.style.display = 'inline'}
          }
     }

}
</script>

Recommended Answers

All 4 Replies

Hi there,

that is a toggle function, used to show and hide elements' inside a page. Maybe its meant to toggle some <div><elements></elements></div> or it can be a ul tag.

Is there anything that we can do to help you on solving this issue?

Thank you..:)
What I intend to do is to show related terms when a keyword is inserted to a textbox.
here is my code

<?php
 $q = $_GET['q'] ;
   $myquery = "select * from terms where term like '%".$q."%' ";
//mysql_free_result(result); 
$result = mysql_query ($myquery); 

while ($row= mysql_fetch_array($result))
{
$term1 = $row["term1"];
$term2 = $row["term2"];
$term3 = $row["term3"];
}
?>

then I combined with the js code that I have posted before..
I coded like this afterwards..

<table cellpadding="0" cellspacing="0" width="950" border="0">
<tr>
 <td><a href="#" onclick="expand(0);return false;"> Expand terms</a></td>

</tr>

<tr id="e0" style="display:none">
<td colspan="99">
            <table border="0">
            <tr><td>Related terms</td>></tr>
            <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
			
            <tr><td><?php echo $term1; ?></td></tr>
            <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
            <tr><td><?php echo $term2; ?></td></tr>
            <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
            <tr><td><?php echo $term3; ?></td></tr>
            <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
            </table>
</td>
</tr>
</table>

however, when I click 'Expand term' after inserting certain keyword,
the list shows the last record in my table terms.
Can anyone tell me what wrong with it?

Your help is much appreciated.

Hi,

Sorry to keep you waiting. Here's your requested sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>http://www.daniweb.com</title>
<style type="text/css">
<!--
.hide { display : none }
.show { display : table-row-group; }
.block { display : block }
-->
</style>
<script type="text/javascript">
<!--
var expand = ( function() {
  return expand = function( sec, disp ) {
var ie, ff;
var disp = (( disp ) ? disp : "show" );
/* http://www.daniweb.com/

NOTICE: 
- I am not imposing anyone to use this script, i'm just doing what is right and what is good for your browser. */


var ua = ((( ie = document.all[ sec ] ) && !!!( ff = document.getElementById( sec ))) ? 1 : 0 ); 
var sec = null || { 0 : ff, 1 : ie }[ ua ];
   sec.className = (( sec.className === disp ) ? "hide" : disp );
 return sec;
   }  
} )( );
// -->
</script>
</head>
<body>
<div id="main">
<table cellpadding="5" cellspacing="5" border="3" id="terms" frame="border" rules="all" summary="Expand terms" width="50%">
<thead>
<tr><td>
<!-- Default display is set to "table-row-group" using single parameter inside the expand("arg1") function -->

<a href="javascript:void(0);" onclick="expand('e0');">Expand Terms : ( display as a table-row-group )</a><br><br><br>
<!-- This an optional display properties, by proving the 2nd arguments' inside the expand( arg1, "arg2" ) function. Your element will then be displayed as a block-level element -->
<a href="javascript:void(0);" onclick="expand('e0', 'block');">Expand Terms : ( display as a block-level )</a></td></tr>
</thead>
<tfoot class="hide">
<tr><td></td></tr>
</tfoot>
<tbody id="e0" class="hide">
<tr><td>Related Terms</td>
</tr>
<tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
<tr><td><?php echo $term1; ?>Sample Term1</td></tr>
<tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
<tr><td><?php echo $term2; ?>Sample Term2</td></tr>
<tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
<tr><td><?php echo $term3; ?>Sample Term3</td></tr>
<tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
</tbody>
</table>
</div>
</body>
</html>

hope it did help...
essential

hello,
Thanks for your explanation..but my previous code does works exactly as I mean,
the problem is it just takes the last record in the table- terms.
can anyone explain why it is so?

many thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.