Hallo i'm very new to javascript and I am familiar with php now i want to create a script that every 10 seconds change different content to display example when a user comes to the website the content is : blablslbslb after 10 seconds its changes to: jajajdjfjd and after 10 seconds to: kakawkqr and then it goes back to the first one and keeps repeatings this (content isjust a example) does anybody knows a tutorial on the web to do this?
Well, you can put a delay on your javascript, put it in a loop, and make it refresh every 10 seconds. But there's a better way of doing this kind of thing, you should check out ajax.
Where is it that the content will come from? Does it need to display new data in real-time or will it only change occasionally? Will the content come from a database? The best method to use will depend on all these circumstances. If the content is coming from a database and you want it to display new data as it is added then AJAX is what you are looking for. Plenty of tutorials out there. If the content is fixed or does not need to load new data, then you could just use php to write the content to a javascript array and iterate through the items. Like: <div id='jContent'></div> <script type="text/javascript"> var myContentDiv = document.getElementById("jContent"); var myContent = new Array(); var c = 0; var myTimer; var delayInMs = 10000; //Ten seconds. //Write these lines with php if the content is from a database. [B]myContent.push("content 1"); myContent.push("content 2"); myContent.push("content 3");[/B] function start() { myTimer = setInterval(function() { myContentDiv.innerHTML = myContent[c]; if(c<(myContent.length - 1)) c++; else c=0; }, delayInMs); } myContentDiv.onmouseover = function() { clearInterval(myTimer); } myContentDiv.onmouseout = function() { start(); } start() </script> Code (markup): This will also pause on mouseover and resume on mouseout. Another option is to load all the content into an array of DIV's and rotate the visibility of each div. This would be a much better option if the content is long and contains html etc.