473,320 Members | 2,107 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,320 software developers and data experts.

Object Required?

So I just started learning HTML and Javascript about a week ago, and while I'm writing this code, I get an error saying "Object Required". I don't understand why the object is required, and how to fix it, so could you please help?

Also, I probably have other errors as well, so if you could suggest any other corrections to my code, that would be great!

The error states that the object is required on line 2, character 1.

The following code is all the Javascript code I have in the head section of my HTML document so far...

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var command=document.getElementById('tc').innerHTML;
  3. function checkCommand() {
  4.   if (command=="add todo") {
  5.     addToDo();
  6.   }
  7. }
  8. function startTime()  {
  9.   var today=new Date();
  10.   var h=today.getHours();
  11.   var m=today.getMinutes();
  12.   var s=today.getSeconds();
  13.   m=checkTime(m);
  14.   s=checkTime(s);
  15.   document.getElementById('time').innerHTML=h+":"+m+":"+s;
  16.   t=setTimeout('startTime()',500);
  17. }
  18. function checkTime(i) {
  19.   if (i<10) {
  20.     i="0" + i;
  21.   }
  22.   return i;
  23. }
  24. function myDate() {
  25.   var d=new Date();
  26.   var year=d.getFullYear();
  27.   var month=d.getMonth()+1;
  28.   var date=d.getDate();
  29.   document.getElementById('date').innerHTML=month+"/"+date+"/"+year;
  30. }
  31. function addToDo() {
  32.   var input=prompt("Type what you need To-Do...","Make it short please!");
  33.   var tdv=document.getElementById('todo').innerHTML;
  34.   if (tdv.length>0) {
  35.     tdv=tdv+"<br />"+input;
  36.   }
  37.   else {
  38.     tdv=input;
  39.   }
  40. }
  41. </script>
  42.  
Thanks!!!
May 4 '10 #1
1 2294
Dormilich
8,658 Expert Mod 8TB
you usually get an "Object required" error, when you execute code before the appropriate HTML has been built (say, if you have your script in the <head> section, line 2 will throw that error, because nothing of the <body> has been rendered yet). the way to go would be to delay any code execution until the page has completed loading, either via window.onload/window.addEventListener()/any such cross-browser event solution.

besides, that is one reason why you should avoid global variables.
May 4 '10 #2

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

Similar topics

2
by: Dave Hammond | last post by:
I've got what should be a simple assignment of either an element value or a default string to a variable, but when the element doesn't exist I get an "Object required" error rather than an...
7
by: google | last post by:
I am trying to use the following ASP code to examine the file names in a folder: Dim fso, f, fl, s, fs Set fso = CreateObject("Scripting.FileSystemObject") Set f =...
2
by: RICHARD BROMBERG | last post by:
I am using Access 200. I have a form which includes text boxes L1, L2 and L3 And a table tblGrades with number fields L1, L2 and L3
2
by: MaxiBrain | last post by:
How can i correct the Run-time error '424" error that says object required. Every of the required object is in their right order. Please help me. lblExtendedPrice.Caption =...
1
by: Eric | last post by:
What does that error means: Object required I try to use List8.AddItem but when i click on . it not shows AddItem in the window Do Until rst.EOF i = i + 1 Me.List8.ItemData(i) =...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
4
by: =?Utf-8?B?cGJsYWNrYnVybg==?= | last post by:
Summary Getting the error message Run time error 424 Object Required when attempting to assign a value to a C# COM visible property of type object. I have created a COM visible class as below ...
3
by: ShyamKrishnegowda | last post by:
We are writing test scripts to our product. In one of the script we are facing an issue. This test script will create a COM component and executes the following function. O1 and O2 are out...
1
by: ShyamKrishnegowda | last post by:
We are writing test scripts to our product. In one of the script we are facing an issue. This test script will create a COM component and executes the following function. O1 and O2 are out...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.