simpli Posted April 6, 2009 Share Posted April 6, 2009 Hi, Anyone can tell me why this function (showHide) isn't being called? Thanks <style type="text/css"> table { position:relative; left:25em; top:6em; } .error{ background-color: red; } tbody.corps{ display:none; } </style> <script type='text/javascript'> function ShowHide( id_tb) { var tablebody = document.getElementById(id_tb) if (tablebody.style.display == ""){ javascript:document.getElementById(id_tb).style.display="none"; }else{ javascript:document.getElementById(id_tb).style.display=""; } } function HideTable( id_tb) { var tablebody = document.getElementById(id_tb) javascript:document.getElementById(id_tb).style.display="none"; } </script> <html><head><title>Resultats</title></head> <body></br><table width=400><tr> <td width=200>Nom/Choix</td><td width=50>Points</td><td width=50>Points bonis</td><td width=50>total</td></tr> <tr TR BGCOLOR="#99CCFF" onclick="ShowHide('tb_isabelle')"><td>isabelle</td><td>0</td><td>0</td><td>0</td></tr> <tbody id="tb_isabelle" class="corps"> </tbody><tr TR BGCOLOR="#99CCFF" onclick="ShowHide('tb_jeanru')"><td>jeanru</td><td>0</td><td>0</td><td>0</td></tr> <tbody id="tb_jeanru" class="corps"><tr><td>Boston en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>New York Rangers en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>Florida en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>Philadelphie en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>San Jose en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>Detroit en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>Calgary en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>Chicago en 4</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>blloo</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>dark</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>do</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>elves</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>jarome</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>martin</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>Pavel Datsyuk</td><td>93</td><td>0</td><td>93</td></tr> <tr bgcolor=" #B4CFEC"><td>racine</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>Sidney Crosby</td><td>99</td><td>0</td><td>99</td></tr> <tr bgcolor=" #B4CFEC"><td>warcraf</td><td>0</td><td>0</td><td>0</td></tr> <tr> <td>Carey Price</td><td>23</td><td>2</td><td>25</td></tr> <tr bgcolor=" #B4CFEC"><td>Finaliste: San Jose</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>Finaliste: boston</td><td>0</td><td>0</td><td>0</td></tr> <tr bgcolor=" #B4CFEC"><td>Champion: boston</td><td>0</td><td>0</td><td>0</td></tr> </tbody><tr TR BGCOLOR="#99CCFF" onclick="ShowHide('tb_patrick01')"><td>patrick01</td><td>0</td><td>0</td><td>0</td></tr> <tbody id="tb_patrick01" class="corps"> </tbody><tr TR BGCOLOR="#99CCFF" onclick="ShowHide('tb_patrick02')"><td>patrick02</td><td>0</td><td>0</td><td>0</td></tr> <tbody id="tb_patrick02" class="corps"> </tbody></table></br> </body></html> Quote Link to comment Share on other sites More sharing options...
Adam Posted April 6, 2009 Share Posted April 6, 2009 Do you get any errors? Have you looked in the error console?? Quote Link to comment Share on other sites More sharing options...
Dtonlinegames Posted April 6, 2009 Share Posted April 6, 2009 I dont mean to be rude but function ShowHide( id_tb) { var tablebody = document.getElementById(id_tb) if (tablebody.style.display == ""){ javascript:document.getElementById(id_tb).style.display="none"; }else{ javascript:document.getElementById(id_tb).style.display=""; } } seemed terrible. try <script type="text/javascript"> <!-- function showHide(state){ if(state ==1){ document.getElementById('').style.display='block'; } else{ document.getElementById('').style.display='none'; } --> </script> just change what you do and dont need to show or hide and pass to the function boolean 1 or 0 for show and hide Quote Link to comment Share on other sites More sharing options...
burningkamikaze Posted April 6, 2009 Share Posted April 6, 2009 I dont mean to be rude but function ShowHide( id_tb) { var tablebody = document.getElementById(id_tb) if (tablebody.style.display == ""){ javascript:document.getElementById(id_tb).style.display="none"; }else{ javascript:document.getElementById(id_tb).style.display=""; } } seemed terrible. try <script type="text/javascript"> <!-- function showHide(state){ if(state ==1){ document.getElementById('').style.display='block'; } else{ document.getElementById('').style.display='none'; } --> </script> just change what you do and dont need to show or hide and pass to the function boolean 1 or 0 for show and hide Setting a table element to display as block presents problems in some browsers. A tbody element should be set to display="table-row-group" although unfortunately IE does not recognise this and you need to use "block" for IE only. Quote Link to comment Share on other sites More sharing options...
simpli Posted April 7, 2009 Author Share Posted April 7, 2009 Hi, thank you for your help but I'm not sure I understand how the code you posted is better. To get the state variable you pass as parameter you are still going to test tablebody.style.display == "", no? Please correct me if I'm wrong. I did some troubleshooting tonight: I do enter the function but it just never change the style so the tbody elements don't show. Any idea why? Quote Link to comment Share on other sites More sharing options...
Adam Posted April 7, 2009 Share Posted April 7, 2009 javascript:document.getElementById(id_tb).style.display="none"; "javascript:" is for inline JavaScript. Also having the style.display = "" could be causing an error, use "block" instead. Try: function ShowHide(id_tb) { var tablebody = document.getElementById(id_tb) if (tablebody.style.display == "block"){ document.getElementById(id_tb).style.display="none"; }else{ document.getElementById(id_tb).style.display="block"; } } Quote Link to comment Share on other sites More sharing options...
Dtonlinegames Posted April 7, 2009 Share Posted April 7, 2009 Also its bad practice to put getElementById onto a single var While it saves you time for IE. Doesnt work in Safari or Opera So as MrAdam said. Take off the javascript: because thats meant for function calling from a link/onclick etc and put block instead because the table-row, table-column attributes for CSS are outdated . Unless you want to expand your script to include a browser checker Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.