Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2009
Posts: 81
Reputation: tulipputih is an unknown quantity at this point 
Solved Threads: 0
tulipputih tulipputih is offline Offline
Junior Poster in Training

Expand function

 
0
  #1
Jul 28th, 2009
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.
  1. <script>
  2. function expand(sec)
  3. {
  4. thisSec = eval('e' + sec);
  5. if (thisSec != null){
  6. if (thisSec.length){
  7. if (thisSec[0].style.display != 'none'){
  8. for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'none'}
  9. }
  10. else{
  11. for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'inline'}
  12. }
  13. }
  14. else{
  15. if (thisSec.style.display != 'none') {thisSec.style.display = 'none'}
  16. else{thisSec.style.display = 'inline'}
  17. }
  18. }
  19.  
  20. }
  21. </script>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Expand function

 
0
  #2
Jul 28th, 2009
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?
Last edited by essential; Jul 28th, 2009 at 6:23 am.
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 81
Reputation: tulipputih is an unknown quantity at this point 
Solved Threads: 0
tulipputih tulipputih is offline Offline
Junior Poster in Training

Re: Expand function

 
0
  #3
Jul 28th, 2009
Thank you..
What I intend to do is to show related terms when a keyword is inserted to a textbox.
here is my code
  1. <?php
  2. $q = $_GET['q'] ;
  3. $myquery = "select * from terms where term like '%".$q."%' ";
  4. //mysql_free_result(result);
  5. $result = mysql_query ($myquery);
  6.  
  7. while ($row= mysql_fetch_array($result))
  8. {
  9. $term1 = $row["term1"];
  10. $term2 = $row["term2"];
  11. $term3 = $row["term3"];
  12. }
  13. ?>
then I combined with the js code that I have posted before..
I coded like this afterwards..
  1. <table cellpadding="0" cellspacing="0" width="950" border="0">
  2. <tr>
  3. <td><a href="#" onclick="expand(0);return false;"> Expand terms</a></td>
  4.  
  5. </tr>
  6.  
  7. <tr id="e0" style="display:none">
  8. <td colspan="99">
  9. <table border="0">
  10. <tr><td>Related terms</td>></tr>
  11. <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
  12.  
  13. <tr><td><?php echo $term1; ?></td></tr>
  14. <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
  15. <tr><td><?php echo $term2; ?></td></tr>
  16. <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
  17. <tr><td><?php echo $term3; ?></td></tr>
  18. <tr><td><img src="space.gif" height="1" width="100%"></td></tr>
  19. </table>
  20. </td>
  21. </tr>
  22. </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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Expand function

 
0
  #4
Jul 28th, 2009
Hi,

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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <meta http-equiv="Content-Script-Type" content="text/javascript">
  8. <title>http://www.daniweb.com</title>
  9. <style type="text/css">
  10. <!--
  11. .hide { display : none }
  12. .show { display : table-row-group; }
  13. .block { display : block }
  14. -->
  15. </style>
  16. <script type="text/javascript">
  17. <!--
  18. var expand = ( function() {
  19. return expand = function( sec, disp ) {
  20. var ie, ff;
  21. var disp = (( disp ) ? disp : "show" );
  22. /* http://www.daniweb.com/
  23.  
  24. NOTICE:
  25. - I am not imposing anyone to use this script, i'm just doing what is right and what is good for your browser. */
  26.  
  27.  
  28. var ua = ((( ie = document.all[ sec ] ) && !!!( ff = document.getElementById( sec ))) ? 1 : 0 );
  29. var sec = null || { 0 : ff, 1 : ie }[ ua ];
  30. sec.className = (( sec.className === disp ) ? "hide" : disp );
  31. return sec;
  32. }
  33. } )( );
  34. // -->
  35. </script>
  36. </head>
  37. <body>
  38. <div id="main">
  39. <table cellpadding="5" cellspacing="5" border="3" id="terms" frame="border" rules="all" summary="Expand terms" width="50%">
  40. <thead>
  41. <tr><td>
  42. <!-- Default display is set to "table-row-group" using single parameter inside the expand("arg1") function -->
  43.  
  44. <a href="javascript:void(0);" onclick="expand('e0');">Expand Terms : ( display as a table-row-group )</a><br><br><br>
  45. <!-- 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 -->
  46. <a href="javascript:void(0);" onclick="expand('e0', 'block');">Expand Terms : ( display as a block-level )</a></td></tr>
  47. </thead>
  48. <tfoot class="hide">
  49. <tr><td></td></tr>
  50. </tfoot>
  51. <tbody id="e0" class="hide">
  52. <tr><td>Related Terms</td>
  53. </tr>
  54. <tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
  55. <tr><td><?php echo $term1; ?>Sample Term1</td></tr>
  56. <tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
  57. <tr><td><?php echo $term2; ?>Sample Term2</td></tr>
  58. <tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
  59. <tr><td><?php echo $term3; ?>Sample Term3</td></tr>
  60. <tr><td><img src="space.gif" height="1" width="100%" alt="spacer"></td></tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. </body>
  65. </html>
  66.  

hope it did help...
essential
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 81
Reputation: tulipputih is an unknown quantity at this point 
Solved Threads: 0
tulipputih tulipputih is offline Offline
Junior Poster in Training

Re: Expand function

 
0
  #5
Jul 30th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC