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(d iv_id).sty le.visibil ity == 'hidden')
{
document.getElementById(im g_name).sr c = 'minus.gif';
document.getElementById(di v_id).styl e.visibili ty = 'visible';
}
else
{
document.getElementById(im g_name).sr c = 'plus.gif';
document.getElementById(di v_id).styl e.visibili ty = '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/gene work/html/ DATA/test" , "r");
while (!feof($Motif_File))
{
$Motif = trim(fgets($Motif_File));
$Seq_File = fopen("/home/websites/gene work/html/ DATA/$Moti f", "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('ar row<?=$Mot ifNum?>', '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
<script type="text/javascript">
function ToggleDisplay(img_name, div_id)
{
if (document.getElementById(d
{
document.getElementById(im
document.getElementById(di
}
else
{
document.getElementById(im
document.getElementById(di
}
}
</script>
Here's the PHP code:
<?php
?>
<table width="500" align="center" border="1">
<tr>
<td align="center"><b>Promoter
</tr>
</table>
<div align="center" style="overflow:auto;">
<?
$MotifNum=0;
$Motif_File = fopen("/home/websites/gene
while (!feof($Motif_File))
{
$Motif = trim(fgets($Motif_File));
$Seq_File = fopen("/home/websites/gene
$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?>"
<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
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.
ASKER
I took out the extra </div> tag; still no luck.
ASKER
Here's the source:
<html>
<head>
<script type="text/javascript">
function ToggleDisplay(img_name, div_id)
{
if (document.getElementById(d iv_id).sty le.visibil ity == 'hidden')
{
document.getElementById(im g_name).sr c = 'minus.gif';
document.getElementById(di v_id).styl e.visibili ty = 'visible';
}
else
{
document.getElementById(im g_name).sr c = 'plus.gif';
document.getElementById(di v_id).styl e.visibili ty = '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('ar row0', 'R0R'); return false;"><b>TTTTTT</b> : Found 3 Times in 1 Gene(s)
<div id="R0R" style="visibility:hidden;" >
>RPC53
TCTTCGTCTTCTAACAGAGAATGGTC ATCATCTTTA TTACTGTCGC CAAAGGTGGA TTGTCCAAGT AAAA
CCTTTTCCCTTTTAGAAGCAAAATCA TCAACTTCGT TTAAACCATA CGGATTAATC TCATCCCCAA CTTC
AGAGGTCTTAGTTCTGTTTGAGCCTT TGCGTACCAT ATTATTCTAT ACACCCACTC TAATATGTTT TCTC
TTCCTCCAAAACTTTTTGTATAAAAG CATCAGTGAG ATGAGCTATG ATGAGATGAG CTTCATTATT GAA<
b>TTTTTT</b>TTCATTGCAGAAGC GCAGTTTGAA AATTTTTCAT CCGCCCTGCA AAGTCCAA<b >TTT
TTT</b>GATCAGCAGAAGATAATGA CCAGAGAATT ATGGTATTCA AGAGAACAAT TCAAAAGAGG ACAG
CTAGAAAGATATTGAGGTATTTATAA TTTGCTAGAC TAACCGAAAG TCGAAGCGTA ATCTTG<b>T TTTT
T</b>ATTAAGCGGGATAGCATTCAT TAAGT
</div>
</div>
<html>
<head>
<script type="text/javascript">
function ToggleDisplay(img_name, div_id)
{
if (document.getElementById(d
{
document.getElementById(im
document.getElementById(di
}
else
{
document.getElementById(im
document.getElementById(di
}
}
</script>
</head>
<body>
<table width="500" align="center" border="1">
<tr>
<td align="center"><b>Promoter
</tr>
</table>
<div style="overflow:auto;">
<IMG NAME="arrow0" SRC="plus.gif" onclick="ToggleDisplay('ar
<div id="R0R" style="visibility:hidden;"
>RPC53
TCTTCGTCTTCTAACAGAGAATGGTC
CCTTTTCCCTTTTAGAAGCAAAATCA
AGAGGTCTTAGTTCTGTTTGAGCCTT
TTCCTCCAAAACTTTTTGTATAAAAG
b>TTTTTT</b>TTCATTGCAGAAGC
TTT</b>GATCAGCAGAAGATAATGA
CTAGAAAGATATTGAGGTATTTATAA
T</b>ATTAAGCGGGATAGCATTCAT
</div>
</div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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.
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!
I added 50 points to the original question, just in case you came back with something :)
Thanks!
Glad to help. Thanks for the points :)
Client-side JavaScript doesn't care what language you use to generate the code, but only what's present in the fully generated page.