0

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";
} }

8
  • So, what's the error console log saying in your browser? Why are you not calling getElementById on the document as 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. Commented May 17, 2013 at 16:54
  • ow damn, thanks :p but it's still not working :S i'm not even getting an alert Commented May 17, 2013 at 16:57
  • You also need to apply @Eugene's fix below. Both these problems will have been clear and visible in your error log in the browser. Commented May 17, 2013 at 16:58
  • did that too, and still nothin, this is what the console says: Uncaught SyntaxError: Unexpected token } Commented May 17, 2013 at 17:01
  • but the brackets seem to be right :S Commented May 17, 2013 at 17:02

1 Answer 1

3

Looks like missing quotes on params values in function call:

 echo "<button id='LeesMeerKnop$teller' class='LeesMeerKnoppen' onclick='readMoreLess(\"LeesMeerKnop$teller\",\"LongReview$teller\")'>Lees meer...</button>";
Sign up to request clarification or add additional context in comments.

1 Comment

added quotes and and document. before the getelement function but it's still doing nothing :S

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.