Consistently inconsistent error regarding the nature of a control -how do I fix this?

Discussion in 'Javascript' started by Ted Byers, Aug 24, 2009.

  1. Ted Byers

    Ted Byers Guest

    Here is the error:
    'edate.value' is null or not an object

    I get at this using the debugger presented by MS IE.

    Here is how the page/form definition begins:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Campaign Definition</title>
    </head>
    <body>
    <h1>Campaign Configuration</h1>
    <br>
    <form name='campaign' id='campaign'
    action='cgi-bin/create_definition.cgi' method=POST
    onSubmit="return verify_data(this)">
    <table>

    And here are two controls that are used in precisely the same way (at
    least on the web page - the differences play out in the perl script
    and DB on the server):
    <tr>
    <td>Campaign start date
    </td>
    <td>
    <input type=text id='sdate' name='sdate' size=10 maxlength=10 />
    (format yyyy-mm-dd)
    </td>
    </tr>
    <tr>
    <td>Campaign end date
    </td>
    <td>
    <input type=text id='edate' name='edate' size=10 maxlength=10 />
    (format yyyy-mm-dd)
    </td>
    </tr>

    And finally, here are the Javascript functions that are in use here
    (with the statement where the script dies clearly flagged):
    <SCRIPT LANGUAGE="Javascript" type="text/javascript">
    function test_date(x) {
    var pattern = /\d\d\d\d-\d\d-\d\d/;
    if (x.length != 10) return false;
    return pattern.test(x);
    }
    function test_time(x) {
    var pattern = /\d\d:\d\d:\d\d/;
    if (x.length != 8) return false;
    return pattern.test(x);
    }
    function test_nws(x) {
    var pattern = /\w+/;
    return !pattern.test(x);
    }
    function verify_data(f) {
    var f1 = test_nws(f.mname.value);
    var f2 = test_nws(f.cname.value);
    var f3 = test_nws(f.sdate.value);
    var f4 = test_nws(f.edate.value);
    var f5 = test_nws(f.stime.value);
    var f6 = test_nws(f.etime.value);
    var f;
    var msg = "";
    if (f1) {
    msg += "You must provide a valid merchant name.\n";
    }
    if (f2) {
    msg += "You must provide a valid campaign name.\n";
    }
    if (!f3) {
    f = test_date(f.sdate.value);
    if (!f) {
    msg += "The start date provided does not have a recognized
    format.\n";
    }
    } else {
    msg += "You must provide a valid start date for your
    campaign.\n";
    }
    if (!f4) {
    ***********************************************************************************************************
    the following statement is where the script apparently dies with the
    error: "'edate.value' is null or not an object"
    ***********************************************************************************************************
    f = test_date(f.edate.value);
    if (!f) {
    msg += "The end date provided does not have a recognized
    format.\n";
    }
    } else {
    msg += "You must provide a valid end date for your campaign.
    \n";
    }
    if (!f5) {
    f = test_time(f.stime.value);
    if (!f) {
    msg += "The start time provided does not have a recognized
    format.\n";
    }
    }
    if (!f6) {
    f = test_time(f.etime.value);
    if (!f) {
    msg += "The start time provided does not have a recognized
    format.\n";
    }
    }
    if (msg) {
    alert(msg);
    return false;
    }
    return true;
    }
    </SCRIPT>

    Now the CONSISTENT behaviour is that all the functions used with the
    input control sdate work as expected, giving the expected boolean
    results for each condition checked for along with the correct contents
    for msg.

    Further, if edate is empty, I get the correct error message. But when
    edate has a value, I get the error message "'edate.value' is null or
    not an object".

    The inconsistency is that sdate and edate are created and used in
    exactly the same way.

    It is clear that test_nws is working correctly. It is also clear,
    from every condition I test for regarding dates, that test_date works
    correctly on sdate. It is likely that test_time works, but I can't
    say for certain because the script aborts before getting to it.

    Fortunately, the cgi script does nothing at present except echo the
    data back to the user in a different format (so I could confirm it was
    getting the correct data), and IT seems to be getting whatever data I
    give to edate.

    I would have expected that if my Javascript or my HTML had an error
    related to my checking dates, it would affect both sdate and edate,
    but I am baffled as to why only edate is affected.

    Any ideas?

    Thanks

    Ted
    Ted Byers, Aug 24, 2009
    #1
    1. Advertising

  2. Re: Consistently inconsistent error regarding the nature of a control- how do I fix this?

    On Aug 24, 5:18 pm, Ted Byers wrote:
    <snip>
    > <form name='campaign' id='campaign'
    > action='cgi-bin/create_definition.cgi' method=POST
    > onSubmit="return verify_data(this)">

    <snip>
    > function verify_data(f) {
    > var f1 = test_nws(f.mname.value);
    > var f2 = test_nws(f.cname.value);
    > var f3 = test_nws(f.sdate.value);
    > var f4 = test_nws(f.edate.value);
    > var f5 = test_nws(f.stime.value);
    > var f6 = test_nws(f.etime.value);
    > var f;
    > var msg = "";
    > if (f1) {
    > msg += "You must provide a valid merchant name.\n";
    > }
    > if (f2) {
    > msg += "You must provide a valid campaign name.\n";
    > }
    > if (!f3) {
    > f = test_date(f.sdate.value);


    If you change the value of - f - here it will no longer be a reference
    to a form object when you next attempt to reference form controls as
    named properties of - f -.

    > if (!f) {
    > msg += "The start date provided does not have a
    > recognized format.\n";
    > }
    > } else {
    > msg += "You must provide a valid start date for your
    > campaign.\n";
    > }
    > if (!f4) {
    > ***************************************************************
    > the following statement is where the script apparently dies with
    > the error: "'edate.value' is null or not an object"
    > ***************************************************************
    > f = test_date(f.edate.value);

    <snip>
    > I would have expected that if my Javascript or my HTML had an
    > error related to my checking dates, it would affect both sdate
    > and edate, but I am baffled as to why only edate is affected.


    That will be because it is your last use of - f.sdate - that assigns
    to - f -.

    Richard.
    Richard Cornford, Aug 24, 2009
    #2
    1. Advertising

  3. Ted Byers

    Ted Byers Guest

    Re: Consistently inconsistent error regarding the nature of a control- how do I fix this?

    On Aug 24, 12:40 pm, Richard Cornford <>
    wrote:
    > On Aug 24, 5:18 pm, Ted Byers wrote:
    > <snip>
    >
    >
    >
    > >     <form name='campaign' id='campaign'
    > >           action='cgi-bin/create_definition.cgi' method=POST
    > >           onSubmit="return verify_data(this)">

    > <snip>
    > >       function verify_data(f) {
    > >         var f1 = test_nws(f.mname.value);
    > >         var f2 = test_nws(f.cname.value);
    > >         var f3 = test_nws(f.sdate.value);
    > >         var f4 = test_nws(f.edate.value);
    > >         var f5 = test_nws(f.stime.value);
    > >         var f6 = test_nws(f.etime.value);
    > >         var f;
    > >         var msg = "";
    > >         if (f1) {
    > >           msg += "You must provide a valid merchant name.\n";
    > >         }
    > >         if (f2) {
    > >           msg += "You must provide a valid campaign name.\n";
    > >         }
    > >         if (!f3) {
    > >           f = test_date(f.sdate.value);

    >
    > If you change the value of - f - here it will no longer be a reference
    > to a form object when you next attempt to reference form controls as
    > named properties of - f -.
    >
    >
    >
    >
    >
    > >           if (!f) {
    > >             msg += "The start date provided does not havea
    > > recognized format.\n";
    > >           }
    > >         } else {
    > >           msg += "You must provide a valid start date for your
    > > campaign.\n";
    > >         }
    > >         if (!f4) {
    > > ***************************************************************
    > > the following statement is where the script apparently dies with
    > > the error: "'edate.value' is null or not an object"
    > > ***************************************************************
    > >           f = test_date(f.edate.value);

    > <snip>
    > > I would have expected that if my Javascript or my HTML had an
    > > error related to my checking dates, it would affect both sdate
    > > and edate, but I am baffled as to why only edate is affected.

    >
    > That will be because it is your last use of - f.sdate - that assigns
    > to - f -.
    >
    > Richard.


    Thanks Richard,

    And thanks for not pointing out what an idiot I am for allowing such a
    name collision.

    Thanks

    Ted
    Ted Byers, Aug 24, 2009
    #3
  4. Re: Consistently inconsistent error regarding the nature of a control- how do I fix this?

    Richard Cornford wrote:
    > On Aug 24, 5:18 pm, Ted Byers wrote:
    > <snip>
    >> <form name='campaign' id='campaign'
    >> action='cgi-bin/create_definition.cgi' method=POST
    >> onSubmit="return verify_data(this)">

    > <snip>
    >> function verify_data(f) {


    // use the elements collection, e.g.
    // var els = f.elements;
    // els.mname.value;

    >> var f1 = test_nws(f.mname.value);
    >> var f2 = test_nws(f.cname.value);
    >> var f3 = test_nws(f.sdate.value);
    >> var f4 = test_nws(f.edate.value);
    >> var f5 = test_nws(f.stime.value);
    >> var f6 = test_nws(f.etime.value);


    // Problem: Don't redeclare a formal parameter value.
    >> var f;


    You'll just confuse yourself (and others) that way.

    It's a good idea to use the - elements - collection, which has standard
    behavior and is widely supported.

    You should also validate the HTML. Drop the closing "/" -- those show up
    in validator errors. Drop the 'LANGUAGE=javascript' and why use upper
    case for your script tag?

    Garrett
    --
    comp.lang.javascript FAQ: http://jibbering.com/faq/
    Garrett Smith, Aug 24, 2009
    #4
  5. Re: Consistently inconsistent error regarding the nature of a control - how do I fix this?

    In comp.lang.javascript message <d78b52da-bd51-4255-8cc4-1be7166dd476@c2
    9g2000yqd.googlegroups.com>, Mon, 24 Aug 2009 09:18:21, Ted Byers
    <> posted:

    > <SCRIPT LANGUAGE="Javascript" type="text/javascript">

    ^^^^ not wanted ^^^^
    > function test_date(x) {
    > var pattern = /\d\d\d\d-\d\d-\d\d/;
    > if (x.length != 10) return false;
    > return pattern.test(x);
    > }
    > function test_time(x) {
    > var pattern = /\d\d:\d\d:\d\d/;
    > if (x.length != 8) return false;
    > return pattern.test(x);
    > }


    If you use ^ and $ at the ends of your patterns, the separate length
    test will not be needed.

    It would be easy enough to validate the date, so that the mistake of
    using dates like April 31 could be trapped. See via sig below.

    The time can be largely validated by using /^[0-2]\d:[0-5]\d:[0-5]\d$/
    and with a little more effort the hours can be checked for <=23.

    With date-and-time that accurate, you should consider whether seasonal
    clock shifts might matter,

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Aug 24, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    533
  2. Replies:
    1
    Views:
    386
    Thangavel M
    Oct 23, 2005
  3. Xah Lee
    Replies:
    22
    Views:
    1,117
    Tim Roberts
    Mar 21, 2006
  4. Xah Lee
    Replies:
    23
    Views:
    1,061
    Tim Roberts
    Mar 21, 2006
  5. Xah Lee
    Replies:
    21
    Views:
    781
    Tim Roberts
    Mar 21, 2006
Loading...

Share This Page