General questions and topics about Xerte Toolkits that don’t fit anywhere else.

Javascript not working

  • ljm_01
  • Onderwerp Auteur
  • Offline
  • Nieuw lid
  • Nieuw lid
Meer
9 jaren 2 maanden geleden #4508 door ljm_01
Javascript not working werd gestart door ljm_01
Hi all,
I'm hoping to add some Javascript to a Plain Text page (hoping to achieve the function of the Bullets page, but with more control) so that text within div tags appear after 3, 6 and 9 seconds.

No, matter where I place the code (as HTML source on the page, or within the Script text box, or split the HTML and Script appropriately on the page) nothing seems to work. However when previewing this code in DreamWeaver it works OK.

Can someone help get this working for me please.

Here's my code...

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>testdoc</title>
<script>
function showText(id,delay){
var elem=document.getElementById(id);
setTimeout(function(){elem.style.visibility='visible';},delay*1000)
}
window.onload=function(){
showText('delayedText1',3);
showText('delayedText2',6);
showText('delayedText3',9);
}
</script>
</head>
<body>
<div id="delayedText1" style="visibility:hidden">this is 3 seconden</div>
<div id="delayedText2" style="visibility:hidden">this is 6 seconden</div>
<div id="delayedText3" style="visibility:hidden">this is 9 seconden</div>
</body>
</html>

Thanks
Lewis

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Meer
9 jaren 2 maanden geleden #4509 door Fay
Beantwoord door Fay in topic Javascript not working
Hi Lewis

I think the problem is probably that you are using the window.onload function to start triggering the appearance of the divs. Because of the way a Xerte project is set up, when the window onload function is triggered the page content doesn't yet exist.

Try this instead...

Code in the page's 'Script' optional property:
Code:
$("#delayedText1, #delayedText2, #delayedText3").hide(); function showText(id,delay){ var elem=$("#" + id); setTimeout(function(){elem.show()},delay*1000) } showText('delayedText1',3); showText('delayedText2',6); showText('delayedText3',9);

The html:
Code:
<div id="delayedText1">Section 1</div> <div id="delayedText2">Section 2</div> <div id="delayedText3">Section 3</div>
De volgende gebruiker (s) zei dank u: ljm_01, janmeeuw

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • ljm_01
  • Onderwerp Auteur
  • Offline
  • Nieuw lid
  • Nieuw lid
Meer
9 jaren 2 maanden geleden #4510 door ljm_01
Beantwoord door ljm_01 in topic Javascript not working
Amazing! Thank you Fay. This works perfectly

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Moderators: ingdon
Tijd voor maken pagina: 0.145 seconden
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo