This is my php code:
<?php
require('connection.php');
$query="select title,content from blogs";
echo '<html><head>';
echo '<link rel="stylesheet" href="blog.css" />';
echo '<script type="text/javascript" src="blog.js"></script></head><body>';
$i=0;
if($result=$mysqli->query($query))
{
while($news=$result->fetch_row())
{
echo "<br /><br /><strong>". $news[0]."</strong><br /><br />";
if(strlen($news[1])>60)
{
$d=0;
$content=explode(" ",$news[1]);
foreach($content as $c)
{
if($d<=60)
{
echo $c." ";
$d++;
}
else
{
if($d==61)
{
echo "<div id=a$i style='visibility:hidden'>";
echo "<a href='#' onclick='toggle(a".$i.")' style='visibility:visible'>Show/Hide</a>";
$i++;
$d++;
}
echo $c." ";
$d++;
if($d==count($content)+1)
{
echo "</div>";
}
}
}
}
else
echo $news[1]."<br /><br />";
}
$result->close();
echo "</body></html>";
}
?>
This is my JavaScript code:
function toggle(id)
{
//document.getElementById('mcontent').value=x++;
//if(x%2==0)
document.getElementById(id).style.visibility="visible";
//else
//document.getElementById('mcontent').style.visibility="hidden";
};
The show hide button is not working.My strategy is to limit text which contains more than 60 words with the show hide button.Once the user clicks the button the hidden div becomes visible and that contains the extra text(namely the text after 60 word count).Div element should always start with a letter so I have append letter 'a' before that.Please help me fix this.
Note: Don't need Jquery solutions or suggestion.I need only to debug the above code.