Link to home
Start Free TrialLog in
Avatar of cdromes
cdromes

asked on

Problems w/ Javascript Function in PHP

I've had success using the following Javascript function in ASP, but I'm currently having no luck whatsoever trying to use it in PHP:

<script type="text/javascript">

function ToggleDisplay(img_name, div_id)
{      
      if (document.getElementById(div_id).style.visibility == 'hidden')
      {
            document.getElementById(img_name).src = 'minus.gif';
            document.getElementById(div_id).style.visibility = 'visible';
      }      
      else
      {
            document.getElementById(img_name).src = 'plus.gif';
            document.getElementById(div_id).style.visibility = 'hidden';
      }      
}
</script>

Here's the PHP code:

<?php

?>
  <table width="500" align="center" border="1">
  <tr>
     <td align="center"><b>Promoter Region</b></td>             
  </tr>
  </table>
 
  <div align="center" style="overflow:auto;">  
<?
$MotifNum=0;
$Motif_File = fopen("/home/websites/genework/html/DATA/test", "r");
while (!feof($Motif_File))
{
   $Motif = trim(fgets($Motif_File));
   $Seq_File = fopen("/home/websites/genework/html/DATA/$Motif", "r");
   $count=1;
   while (!feof($Seq_File))
   {
      $line = trim(fgets($Seq_File));
        switch($count)
        {
          case 1:
           $TotalFound = $line;
             $count++;
             break;
        case 2:
           $TotalGenes = $line;
             $count++;
           break;
        case 3:
             $ExpectProb = $line;
           $count++;
           break;
          case 4:
         ?><tr><IMG NAME="arrow<?=$MotifNum?>" SRC="plus.gif" onclick="ToggleDisplay('arrow<?=$MotifNum?>', 'R<?=$MotifNum?>R'); return false;"><b><?=$Motif?></b> : Found <?=$TotalFound?> Times in <?=$TotalGenes?> Gene(s)
             <div id="R<?=$MotifNum?>R" style="visibility:hidden;">
           <?
           $count++;
         break;
      }
        if ($count>4)
        {
           echo"$line\n";
      }
   }
   fclose($Seq_File);
 ?></div></tr><?
   $MotifNum++;
}
fclose($Motif_File);
?>
</div></table></body>
</html>

The nutshell version of the above is that for every Motif listed in the file 'test', there's a corresponding file in the same directory with a number of sequences that contain that motif.  So, everytime a user clicks on the gif next to the Motif, the sequences become visible.  Otherwise, they remain hidden.  As stated, this function and the function call worked in ASP, but it's not here, so I'm curious as to whether there are PHP-specific issues for which I should be looking.

Jason
Avatar of BraveBrain
BraveBrain
Flag of Norway image

Any chance we can see the generated code (as from view Source in the browser)?

Client-side JavaScript doesn't care what language you use to generate the code, but only what's present in the fully generated page.
I'm guessing though that it doesn't work because of more opening divs than closing div, so if you don't want to paste the generated page source look for that.
Avatar of cdromes
cdromes

ASKER

I took out the extra </div> tag; still no luck.
Avatar of cdromes

ASKER

Here's the source:

<html>
<head>
<script type="text/javascript">

function ToggleDisplay(img_name, div_id)
{      
      if (document.getElementById(div_id).style.visibility == 'hidden')
      {
            document.getElementById(img_name).src = 'minus.gif';
            document.getElementById(div_id).style.visibility = 'visible';
      }      
      else
      {
            document.getElementById(img_name).src = 'plus.gif';
            document.getElementById(div_id).style.visibility = 'hidden';
      }      
}
</script>
</head>
<body>
  <table width="500" align="center" border="1">
  <tr>
     <td align="center"><b>Promoter Region</b></td>             
  </tr>
  </table>
  <div style="overflow:auto;">

<IMG NAME="arrow0" SRC="plus.gif" onclick="ToggleDisplay('arrow0', 'R0R'); return false;"><b>TTTTTT</b> : Found 3 Times in 1 Gene(s)
             <div id="R0R" style="visibility:hidden;">
           >RPC53
TCTTCGTCTTCTAACAGAGAATGGTCATCATCTTTATTACTGTCGCCAAAGGTGGATTGTCCAAGTAAAA
CCTTTTCCCTTTTAGAAGCAAAATCATCAACTTCGTTTAAACCATACGGATTAATCTCATCCCCAACTTC
AGAGGTCTTAGTTCTGTTTGAGCCTTTGCGTACCATATTATTCTATACACCCACTCTAATATGTTTTCTC
TTCCTCCAAAACTTTTTGTATAAAAGCATCAGTGAGATGAGCTATGATGAGATGAGCTTCATTATTGAA<
b>TTTTTT</b>TTCATTGCAGAAGCGCAGTTTGAAAATTTTTCATCCGCCCTGCAAAGTCCAA<b>TTT
TTT</b>GATCAGCAGAAGATAATGACCAGAGAATTATGGTATTCAAGAGAACAATTCAAAAGAGGACAG
CTAGAAAGATATTGAGGTATTTATAATTTGCTAGACTAACCGAAAGTCGAAGCGTAATCTTG<b>TTTTT
T</b>ATTAAGCGGGATAGCATTCATTAAGT

</div>
</div>
ASKER CERTIFIED SOLUTION
Avatar of BraveBrain
BraveBrain
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdromes

ASKER

Choice #1 worked.  It's odd, indeed, that the original worked in IE, though.

While I've got you "on the phone", if you look at line 4 of the genetic sequence above underneath '>RPC53' you'll see that the < part of the <b> tag got chopped...I did all the parsing and pattern matching in Perl and everything works like a champ, but when I measure out 70 characters in the sequence for each line, occasionally I chop up part of a <b> or a </b> tag.  

Do you know of any efficient way of catching this and fixing it prior to throwing it to the screen?  
My first thought: Replace all occurences of <b> and </b> with i.e. { and } in the original files (so that they only use 1 character space each). Then change it back when echoing it.
Avatar of cdromes

ASKER

That's a pretty good idea...have Perl slap the brackets into the string then replace them in PHP.  

I added 50 points to the original question, just in case you came back with something :)  

Thanks!
Glad to help. Thanks for the points :)