I'm trying to call a js function from the OnClick within multiple DIVs, it passes a 'Section Name' secOther001, 002, 003 etc...'.
<?php
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$TaskID=sprintf("%03d",mysql_result($result,$i,"TaskID"));
$secOthersID = "SecOther$TaskID";
echo "
<div class='clTaskSection' onclick='SecOtherVisibility($secOthersID)'>...</div>
<div id='$secOthersID' class='clTaskSection'>content...</div>";
$i++;
}
?>
it should then call the js below, providing the relevant section name:
<script>
function SecOtherVisibility(divName) {
if (document.getElementById(divName).style.display = "none") {
document.getElementById(divName).style.display = "block"
} else {
document.getElementById(divName).style.display = "none";
}
}
</script>
But I get Uncaught TypeError: Cannot read property 'style' of null. Where am I going wrong?
$secOthersIDdefined?==needed in theif;)