I get an "Error: Object expected" and I don't know why

D

Danny

Hi I don't understand why I keep getting "Error: Object expected" I
tried different things and haven't been able to solve it. I'm a newbie
so I'm not sure what I'm doing wrong. The debugger breaks at the
<BODY> Tag of my code so I'm thinking the problem is with my
InitPage() function. I appreciate the advice. Here is my code.

<SCRIPT LANGUAGE="Javascript">
<!--

var flag = false;

function InitPage()
{

document.MyForm.Datebox.value = getCurrentDate();
}


function MyForm_onsubmit()
{

// Check Date Open Box
if ( checkDate(document.MyForm.Datebox.value) == false )
{ alert("You must provide a Date")
return false;
}
}

// -->
</SCRIPT>

<HTML>
<HEAD>
<TITLE>Dummy Title </Title>
</HEAD>
<BODY onload="InitPage();" bgColor=#0a357e text=White Link=White
vLink=White aLink=White>
<form name = "MyForm" method="post" action="addIssue.asp"
onsubmit= "return MyForm_onsubmit()" >

Date Opened <input name="Datebox">&nbsp;Format: dd/mm/YYYY &nbsp;
<input type="submit" value="Save Details" name="Save_Button">&nbsp;
<input type="reset" value="Clear Details" name="Clear_Button">
</form>
</BODY>
</HTML>
 
L

Lasse Reichstein Nielsen

Hi I don't understand why I keep getting "Error: Object expected" I
tried different things and haven't been able to solve it. I'm a newbie
so I'm not sure what I'm doing wrong. The debugger breaks at the
<BODY> Tag of my code so I'm thinking the problem is with my
InitPage() function. I appreciate the advice. Here is my code.

<SCRIPT LANGUAGE="Javascript">

<script type="text/javascript">
The type attribute is mandatory in HTML 4, the language attribute is
deprecated.

This HTML comment is not needed in Javascript.
var flag = false;

function InitPage()
{
document.MyForm.Datebox.value = getCurrentDate();

I recommend writing
document.forms['MyForm'].elements['Datebox'].value = ...
but that is just a personal peeve.

The problem seems to be that the "getCurrentDate" function is not
defined anywhere.
// -->
unneeded.

</SCRIPT>

<HTML>

Script elements must be inside either head or body. It is illegal to
put them before said:
<HEAD>
<TITLE>Dummy Title </Title>
</HEAD>
<BODY onload="InitPage();" bgColor=#0a357e text=White Link=White

bgColor="#0a357a"
Unquoted attributes are not allowed to contain the character "#".
(Just quote all attributes, and you can stop worrying :).


Hope this helps.
/L
 
L

Lee

(e-mail address removed) said:
Hi I don't understand why I keep getting "Error: Object expected" I
tried different things and haven't been able to solve it. I'm a newbie
so I'm not sure what I'm doing wrong. The debugger breaks at the
<BODY> Tag of my code so I'm thinking the problem is with my
InitPage() function. I appreciate the advice. Here is my code.

function InitPage()
{

document.MyForm.Datebox.value = getCurrentDate();
}

You don't seem to have defined a function called getCurrentDate();
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in news:comp.lang.javascript said:
Hi I don't understand why I keep getting "Error: Object expected" I
tried different things and haven't been able to solve it. I'm a newbie
so I'm not sure what I'm doing wrong. The debugger breaks at the
<BODY> Tag of my code so I'm thinking the problem is with my
InitPage() function. I appreciate the advice. Here is my code.
...

When embedding script in HTML, it is desirable that the HTML itself
should be valid. In the opinion of W3's TIDY (30 Apr 2000) which I got
from http://www.w3.org/People/Raggett/tidy/ yours is not.

Tidy (vers 30th April 2000) Parsing console input (stdin)
line 1 column 1 - Warning: <script> lacks "type" attribute
line 26 column 1 - Warning: inserting missing 'title' element
line 27 column 1 - Warning: <head> isn't allowed in <body> elements
line 28 column 1 - Warning: <title> isn't allowed in <body> elements
line 29 column 1 - Warning: </head> isn't allowed in <body> elements
line 30 column 1 - Warning: <body> isn't allowed in <body> elements

HTML Tidy for Windows released on 1st February 2003 has 8 further
complaints.


While HTML errors do not necessarily prevent script from working, those
look important.

Otherwise, be sure that all objects used are pre-existent or are first
created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top