Can you use PHP 'while' $count in Javascript?
Posted: Tue Feb 12, 2013 1:13 pm
I have a page that uses Javascript to toggle Divs to reveal and hide.
This is what I am trying to write:
As you can see, I'm trying to create it so the numbers appear in the Javascript.
I know JS is browser based, and PHP is client based, but can you use it in this way? If you can, how am I going wrong with this?
This is what I am trying to write:
Code: Select all
<?php
$count = 0;
while ($count < 10) {
$count = $count + 1;
echo "<script language=\"javascript\">
function toggle$count() {
var ele = document.getElementById(\"toggleText$count\");
var text = document.getElementById(\"displayText$count\");
if(ele.style.display == \"block\") {
ele.style.display = \"none\";
text.innerHTML = \"(view info) \";
}
else {
ele.style.display = \"block\";
text.innerHTML = \"(close info) \";
}
}
</script>";
}
?>I know JS is browser based, and PHP is client based, but can you use it in this way? If you can, how am I going wrong with this?