i'm using php to generate some button that have their Id and the Id of the text they should show as parameters. But for some reason the function call doesn't seem to be working.
while($row=$query->fetch(PDO::FETCH_BOTH)) { $reviewDoor=$row[0]; $korteTekst=$row[1]; $langeTekst=$row[2];
echo "<article><h4>Review van $reviewDoor</h4>"; echo "<section>$korteTekst</section>"; if (!empty($langeTekst)) { echo "<section id='LongReview$teller' class='LongReviews'>$langeTekst</section>"; echo "<button id='LeesMeerKnop$teller' class='LeesMeerKnoppen' onclick='readMoreLess(LeesMeerKnop$teller,LongReview$teller)'>Lees meer...</button>"; } echo "</article>"; $teller++;}
the file link is working
<script src="script.js" type="text/javascript"></script>
and this is the function I'm trying to call
function readMoreLess(knopId,tekst) {
var knop=getElementById(knopId);
var review=getElementById(tekst);window.alert("hallo");
if (knop.textContent ==="Lees meer...")
{
knop.textContent="Minder tekst..."; review.style.display="block"; }
else if (knop.textContent ==="Minder tekst...") { knop.textContent="Lees meer..."; review.style.display="none";
} }
getElementByIdon thedocumentas you should? And please, while Dutch is a great language, try to be at least slightly consistent. Either use English like the rest of the world or name all your variables, IDs and functions in your own language.