Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-05-2010, 12:12 AM   PM User | #1
codelook
New Coder

 
Join Date: Dec 2010
Posts: 22
Thanks: 3
Thanked 1 Time in 1 Post
codelook is an unknown quantity at this point
Div content change after 10 seconds?

I want a code that changes text (of maybe a div) after 10 seconds.
So like i could have some text and a link on my page then after 10 seconds it will change to something else and i can make it change to as many things as i want. Then when it goes threw them all it starts over.

THANKS
codelook is offline   Reply With Quote
Old 12-05-2010, 01:21 AM   PM User | #2
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
Code:
<script type="text/javascript">
var content=["<a href='www.url.com'> link 1 </a>",
             "< a href='www.url2.com'> link 2 </a>",
             "insert html content"]
function change(){
           var new=foo.shift()
           document.getElementById('change').innerHTML=new;
           foo[foo.size-1]=new
}
setInterval(change, 10000);
</script>

<div id="change"> </change>
gizmo1650 is offline   Reply With Quote
Users who have thanked gizmo1650 for this post:
codelook (12-05-2010)
Old 12-05-2010, 02:30 AM   PM User | #3
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,797
Thanks: 30
Thanked 462 Times in 456 Posts
jmrker will become famous soon enough
Lightbulb Modified script ...

I tweeked 'gizmo1650's script just a bit for testing purposes.
Code:
<script type="text/javascript">
// From: http://www.codingforums.com/showthread.php?t=211050

var content = [
  "<a href='www.url.com'> link 1 </a>",
  "<a href='www.url2.com'> link 2 </a>",
  "insert html content"
];
var msgPtr = 0;
var stopAction = null;

function change() {
  var newMsg = content[msgPtr];
  document.getElementById('change').innerHTML = 'Message: '+msgPtr+'<p>'+newMsg;
  msgPtr++;  msgPtr = (msgPtr % content.length);
}

function startFunction() { change();  stopAction = setInterval(change, 5000); }
function stopFunction() { clearInterval(stopAction); }

</script>

<button onclick="startFunction()">Start</button>
<button onclick="stopFunction()">Stop</button>
<div id="change" style="border:5px solid red;width:300px; height:200px;background-Color:yellow"> </div>
He was on the right track, just needed some mods.
jmrker is offline   Reply With Quote
Users who have thanked jmrker for this post:
codelook (12-05-2010)
Old 12-05-2010, 04:27 AM   PM User | #4
codelook
New Coder

 
Join Date: Dec 2010
Posts: 22
Thanks: 3
Thanked 1 Time in 1 Post
codelook is an unknown quantity at this point
Thumbs up Thanks

This is great! it will do exactly what i want!!
codelook is offline   Reply With Quote
Old 12-05-2010, 04:59 AM   PM User | #5
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,797
Thanks: 30
Thanked 462 Times in 456 Posts
jmrker will become famous soon enough
Arrow

Quote:
Originally Posted by codelook View Post
This is great! it will do exactly what i want!!
You're most welcome.
Happy to help, I'm sure, from both of us.
Good Luck!
jmrker is offline   Reply With Quote
Old 12-05-2010, 02:34 PM   PM User | #6
codelook
New Coder

 
Join Date: Dec 2010
Posts: 22
Thanks: 3
Thanked 1 Time in 1 Post
codelook is an unknown quantity at this point
sorry but i couldn't get it to start automatically any help?
codelook is offline   Reply With Quote
Old 12-05-2010, 06:01 PM   PM User | #7
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,797
Thanks: 30
Thanked 462 Times in 456 Posts
jmrker will become famous soon enough
Lightbulb

Quote:
Originally Posted by codelook View Post
sorry but i couldn't get it to start automatically any help?
Code:
....
onload = function() {
  startFunction(); 
}
</script>
....
jmrker is offline   Reply With Quote
Old 12-05-2010, 08:11 PM   PM User | #8
codelook
New Coder

 
Join Date: Dec 2010
Posts: 22
Thanks: 3
Thanked 1 Time in 1 Post
codelook is an unknown quantity at this point
thanks again
codelook is offline   Reply With Quote
Old 07-21-2012, 05:35 AM   PM User | #9
shunail
New to the CF scene

 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
shunail is an unknown quantity at this point
Change background after 20 seconds or so

Hi,
is it possible to change the background color of a webpage from black to white after 20 seconds or so? Please help. Thanks
shunail is offline   Reply With Quote
Old 07-21-2012, 07:57 AM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by shunail View Post
Hi,
is it possible to change the background color of a webpage from black to white after 20 seconds or so? Please help. Thanks
Yes, of course it is possible. But this is so simple that you ought to Google for the answer.
And please do not revive some long-finished thread. Prefer to start a new thread of your own.

Here you are:-

Code:
<script type = "text/javascript">

document.bgColor = 'black';
setTimeout(changeBGC, 20000);  // 20 seconds

function changeBGC(){
document.bgColor = 'white';
}
</script>
"99.9 percent of lawyers give the rest a bad name." - Unknown
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 07-21-2012 at 08:12 AM..
Philip M is offline   Reply With Quote
Old 07-22-2012, 10:52 PM   PM User | #11
shunail
New to the CF scene

 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
shunail is an unknown quantity at this point
Thanks SO MUCH Philip. I did searched Google but only thing I found was random colors scripts, named Disco Script. Thanks for the code
shunail is offline   Reply With Quote
Reply

Bookmarks

Tags
change, div, timeout

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:56 AM.


Advertisement
Log in to turn off these ads.