473,324 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

JavaScript Counter Error

HawkNail
Long story short, I'm making an online test to help prepare some buddies for an online math test. The test is timed and so I am trying to put in a counter to count down to zero. My code looks like this:

Expand|Select|Wrap|Line Numbers
  1. function clock()
  2. {
  3.     if (document.clock.display.value>0){
  4.     setTimeout("clock()",60);
  5.     document.clock.display.value = document.clock.display.value - 1;
  6.     document.clock.display.write("document.clock.display.value");
  7.     document.clock.display.close();
  8.     }
  9.     else {
  10.     alert("Your time is up!");
  11.     }
  12. }
  13.  
It is started by an onLoad from the body tag. It links to:

Expand|Select|Wrap|Line Numbers
  1. <form name="clock">
  2. <input type="textarea" name="display" value="30">
  3. </form>
  4.  
Now the thing is - it works, and it gets to zero and throws up the alert. However, IE is bent on telling me that the "object doesn't support that property or method". What's going on here? Sure it works, but I'm kind of a perfectionist and bad code is not okay.
Mar 30 '10 #1

✓ answered by RamananKalirajan

Why you have used this line.

Expand|Select|Wrap|Line Numbers
  1.  document.clock.display.write("document.clock.display.value");
Thanks and Regards
Ramanan Kalirajan

4 2019
RamananKalirajan
608 512MB
Why you have used this line.

Expand|Select|Wrap|Line Numbers
  1.  document.clock.display.write("document.clock.display.value");
Thanks and Regards
Ramanan Kalirajan
Mar 30 '10 #2
I used that line to rewrite the value of the "clock" so it is visible to the user - but I just tried it w/o that line and it worked. So thanks for the answer, but would you care to explain how it works now?
Mar 30 '10 #3
gits
5,390 Expert Mod 4TB
using document.write() after a page is fully rendered destroys the DOM and so it will not work anymore ... it is not suggested to use that after a page is loaded ... you could always use other methods ...

kind regards
Mar 30 '10 #4
RamananKalirajan
608 512MB
Well Said Gits.

@HawkNail,

Expand|Select|Wrap|Line Numbers
  1. document.clock.display.value = document.clock.display.value - 1;
This line will do your desired work. Again using document.write for the same object will leads to error. You can use document.write before loading the page or on the load of the page. To edit the contents after the page is loaded use DOM functionality as "Gits" said


Thanks and Regards
Ramanan Kalirajan
Mar 31 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Leila | last post by:
Hi folks, I have a fairly complex xml document which looks like this: <my:InsideView xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-02T14:22:59" xml:lang="en-us">...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
6
by: Geoff | last post by:
Here's the situation. I have a static html page which we want to update to include some dynamic content. I want a counter that keeps track of the number of times anyone presses the "add" button,...
6
by: sakms | last post by:
I am attempting to validate radio buttons in Netscape with JavaScript. Everything works excellent in Explorer, but refuses to work in Netscape (all versions). =========== JAVASCRIPT CODE...
3
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. ...
4
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
9
by: brett | last post by:
I'd like to execute javascript if I'm in a certain directory. I can't figure out how to render the javascript script below. I always end up with some type of parsing error. Any suggestions? ...
1
by: theflyingminstrel | last post by:
Hi, I’m having some trouble with a Javascript code, and I was wondering if anyone can help: I am trying to build a price estimator that has multiple fields. I would like the first two fields to...
6
by: vijeberal | last post by:
Hi all, I am working on a GridView and there exist a Checkbox control .. iplaced another checkbox in header also i have written a javascript for selection of checkboxex fro e.g if you click on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.