[SOLVED] why isnt my javascript displaying the text

This is a discussion on "[SOLVED] why isnt my javascript displaying the text" within the JavaScript Forum section. This forum, and the thread "[SOLVED] why isnt my javascript displaying the text are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 26th, 2008, 11:48
Junior Member
Join Date: Dec 2007
Location: UK
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] why isnt my javascript displaying the text

hi, i have written the following javascript, however when i click the button it wont display the text. can anyone see what the problem is and how to get it working. i am trying to do it so the text is displayed in a sequence.
thanks
HTML: Select all
<html>
<head>
<script type="text/javascript">
function timedText()
{
var t1=setTimeout("document.getElementById('displayDiv').value='2 seconds!'",2000);
var t2=setTimeout("document.getElementById('displayDiv').value='4 seconds!'",4000);
var t3=setTimeout("document.getElementById('displayDiv').value='6 seconds!'",6000);
}
</script>
</head>
<body>
<form>
<input type="button" value="Display timed text!" onClick="timedText()">
<div id="displayDiv">
</div>
<p>Click on the button above. It will tell you when two, four, and six seconds have passed.</p>
</body>
</html>

Last edited by Rakuli; Jan 26th, 2008 at 12:05. Reason: Please use [html][/html] tags when posting html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 26th, 2008, 12:04
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: why isnt my javascript displaying the text

Your problem is that you can't set the value of a div -- you have to change it's contents and re-wriote the HTML..

Change these lines

var t1=setTimeout("document.getElementById('displayDiv ').value='2 seconds!'",2000);


to

var t1=setTimeout("document.getElementById('displayDiv ').innerHTML='2 seconds!'",2000);

so that it rewrites the HTML.

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 26th, 2008, 18:48
Junior Member
Join Date: Dec 2007
Location: UK
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Re: why isnt my javascript displaying the text

thanks so much, what u suggested was right and works now,

do you know how i can keep the text that on the page for example, 2seconds, 4 seconds and 6 seconds will stay on the page once displayed rather than disappear when another thing is called
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 26th, 2008, 20:43
Junior Member
Join Date: Dec 2007
Location: UK
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Re: why isnt my javascript displaying the text

its ok i have solved the problem, i will mark the post as solved now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying text for a set amount of time smudge618 JavaScript Forum 1 Feb 5th, 2008 13:39
[SOLVED] div isnt moving down danny322 Web Page Design 1 Dec 3rd, 2007 12:35
[SOLVED] Image with text -&gt; text with background alexgeek Web Page Design 5 Nov 13th, 2007 23:25
Please Help with hiding and displaying layers using CSS and Javascript rosh1e JavaScript Forum 2 Apr 15th, 2007 03:04
Javascript menu not displaying correclty AdRock Web Page Design 11 Sep 26th, 2006 13:53


All times are GMT. The time now is 01:51.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42