Jump to content

Recommended Posts

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> 




Link to comment
https://forums.phpfreaks.com/topic/152780-why-is-this-function-not-executing/
Share on other sites

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  ;)

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.

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?

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";
   }
}

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.