Forum Moderators: open

Message Too Old, No Replies

Very Cool Effect : The only thing is it doesn't work

Guys, this script is not working the way I wanted it to.

         

haryanto

7:22 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Hi guys.

I wanted to create an effect of a textbox that changes content fast.
For some reason it only displays the last line: "right" instead of creating a nice content changing effect.
For a preview of this effect, go to:

Below is just an example.
I have like thousands of lines to display instead of the "whatever" and "right". This example might seem to be very stupid but I have a real world application for it. What do I have to do to make it work?
Please help me out! Thanks in advance!

<form name="form1">
<input name="txtOne" type="text" size="100">
<script language="JavaScript">
document.forms[0].txtOne.value = "whatever";
document.forms[0].txtOne.value = "what";
document.forms[0].txtOne.value = "yeah";
document.forms[0].txtOne.value = "right";
</script>
</form>

[edited by: jatar_k at 3:13 pm (utc) on Oct. 5, 2005]
[edit reason] removed url [/edit]

Bernard Marx

8:11 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It may be a good idea to try counting down to some point in the future instead. :)

haryanto

8:13 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Bernard,

Can you please help me by elaborating on that point?

Bernard Marx

8:22 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The point that you are currently attempting to count down to is

event = new Date("Sep 29 2001 00:00:01");

That date is in the past (by my watch). Try changing the year to 2004. You'll find that the script does work.

It may be better, afterwards, to change your referencing to a stricter style. eg:

document.form1.days.value = days;
// to
document.forms['form1'].elements['days'].value = days;

haryanto

8:38 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Bernard,

Sorry for the confusion.
The script that I am talking about is:
<form name="form1">
<input name="txtOne" type="text" size="100">
<script language="JavaScript">
document.forms[0].txtOne.value = "whatever";
document.forms[0].txtOne.value = "what";
document.forms[0].txtOne.value = "yeah";
document.forms[0].txtOne.value = "right";
</script>
</form>

The website link is only for visualizing changing content effect. Nothing to do with my script actually. ;-)
Sorry for that.

Bernard Marx

9:27 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




var values = 
[
'whatever',
'what',
'yeah',
'right'//
]

var iCurrValue = 0
var delay = 1000

function changeValue()
{
document.forms[0].txtOne.value = values[iCurrValue++]
setTimeout("changeValue()",delay)
}

haryanto

10:00 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Is this right? It doesnt seem to work though.

<form name="form1">
<input name="txtOne" type="text" size="100">
<script language="JavaScript">
var values = [ 'whatever', 'what', 'yeah', 'right']
var iCurrValue = 0 var delay = 1000
function changeValue()
{
document.forms[0].txtOne.value = values[iCurrValue++]
setTimeout("changeValue()",delay)
}
</script>
</form>

Bernard Marx

10:27 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to call the function too:

<form name="form1"> 
<input name="txtOne" type="text" size="100">

</form>
<script language="JavaScript">
var values = [ 'whatever', 'what', 'yeah', 'right'];
var iCurrValue = 0;
var delay = 1000;
changeValue();
function changeValue()
{
document.forms[0].txtOne.value = values[iCurrValue++];
setTimeout("changeValue()",delay);
}
</script>

haryanto

11:13 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Hi Mr Marx,

Thank you so much.
You solution works and I just realized mine works too!
I was just a tad too careless in my coding.
Shabby coding is unforgivable. ;-)