Link to home
Start Free TrialLog in
Avatar of omb
omb

asked on

Java / DHTML question

I am looking to display text on an HTML page which changes every x seconds. For example, a sentence might read: "Last minute offers on the following: Florida, Jamaica, Greece". I would like the named places to change in order from Florida, then Jamaica and then Greece etc.

Any ideas how I go about doing this? I assume the code references an array of text to be displayed at different time intervals.

Can anyone supply me with the code to do this please? I've not done much java or dhtml before - go easy with me!

Thanks for your help.
Avatar of PBall
PBall

Hmm, bunch of ways to implement this.

compatibility vs. look

for compatibility, you need to put the "dynamic" text inside a textbox / textarea and use setTimeout javascript function to switch between the messages.

sample code:

var arrText = new Array("Last minute offers on the following:","Florida","Jamaica","Greece");
var lngIndex = 0;

function switchText() {
  document.frmSomething.txtFlasher.value = arrText[lngIndex]

lngIndex = (lngIndex+1 < arrText.length) ? lngIndex++:0;

//call this function back every 5 seconds.
setTimeout("switchText()",5000);
}

or a separate frame that use META REFRESH / javascript to update the frame w/ different HTML source every so often.

for look you can experiment w/ DHTML for 4.0 browsers which I won't go into, you can look up a lot of reusable DHTML components such as this (also step by step instruction) on www.webreference.com/dhtml
You could also think about setting up an animated gif.
or flash...
Avatar of omb

ASKER

PBall - thanks for your javascript. Unfortunately, I can't seem to get it to work. I am new to coding & not really quite sure where to put the sample you've given me. Please could you please give me a sample of the html you embed this javascript in. Basically a plain text page with a line of text and then the 'dynamic' text changing.

Currently I use an animated gif - that's fine but a real pain when I need to change the text & have to re-optimised. Flash would be fine too, but surfers require a plug-in & I don't want to narrow my audience down to just see some animated text.

Thanks so much for all your useful comments.
Avatar of omb

ASKER

PBall - sorry, but I still can't get this to work... are you able to help me any further?

Thanks
Avatar of omb

ASKER

Anyone able to offer me further help on this javascript?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of bri53
bri53

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial