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

Discussion in 'Javascript' started by Danny, Jul 18, 2003.

  1. Danny

    Danny Guest

    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;

    // -->

    <TITLE>Dummy Title </Title>
    <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">
    Danny, Jul 18, 2003
    1. Advertisements

  2. <script type="text/javascript">
    The type attribute is mandatory in HTML 4, the language attribute is
    This HTML comment is not needed in Javascript.
    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.
    Script elements must be inside either head or body. It is illegal to
    Unquoted attributes are not allowed to contain the character "#".
    (Just quote all attributes, and you can stop worrying :).

    Hope this helps.
    Lasse Reichstein Nielsen, Jul 18, 2003
    1. Advertisements

  3. Danny

    Lee Guest

    You don't seem to have defined a function called getCurrentDate();
    Lee, Jul 18, 2003
  4. JRS: In article <>, seen
    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

    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
    Dr John Stockton, Jul 18, 2003
  5. Danny

    Danny Guest

    It finally works. Thanks for the help.

    Danny, Jul 18, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.