Object expected; can't find it. Need another pair of eyes.

Discussion in 'Javascript' started by Laiverd.COM, Aug 5, 2004.

  1. Laiverd.COM

    Laiverd.COM Guest

    Hi, In the following function I keep getting a 'Object expected at line 75
    char 5' but for the life of me I cannot find the error. Maybe someone would
    be so kin to have a look? I indicated the 'problem' line below in the
    function.

    function checkEmail(f){
    // check for a valid emailadress
    var field = f;
    // alert(field.value);
    var str = field.value;
    if (str == ""){
    errors += "[ " + field.name.toUpperCase() + " ] is een verplicht veld.\n";
    } else if (str != "") {
    // if the browser supports window.RegExp
    if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str =
    "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str)){
    // emailadress is correct
    return true;
    } else {
    errors += "[ " + str + " ] is een onjuist emailadres.\n";
    ////////////////////////////////////////////// THIS IS SUPPOSED TO BE A
    PROBLEM
    return false;
    }
    // if the browser does not support window.RegExp
    } else {
    if(str.indexOf("@") >= 0){
    errors += "[ " + str + " ] is een onjuist emailadres.\n";
    }
    }

    }
    }

    Thanks for lending me your eyes and wisdom.

    John

    --
    ----------------------------------------------------------------------------
    -----------
    RESOURCES
    http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
    ----------------------------------------------------------------------------
    -----------
    TUTORIALS at
    www.laiverd.com
    Flash & PHP Emailform
    Using textfiles in Flash
    ----------------------------------------------------------------------------
    -----------
     
    Laiverd.COM, Aug 5, 2004
    #1
    1. Advertising

  2. Laiverd.COM

    kaeli Guest

    In article <4112283a$0$62395$>,
    enlightened us with...
    > Hi, In the following function I keep getting a 'Object expected at line 75
    > char 5' but for the life of me I cannot find the error. Maybe someone would
    > be so kin to have a look? I indicated the 'problem' line below in the
    > function.
    >
    > function checkEmail(f){


    You never verify that the code that calls this function actually passes a
    non-null string.
    You should do that just for more stable code.

    > // check for a valid emailadress
    > var field = f;
    > // alert(field.value);
    > var str = field.value;


    See, if someone passes you a null object, there won't be a value. This will
    error out.

    > if (str == ""){
    > errors += "[ " + field.name.toUpperCase() + " ] is een verplicht veld.\n";


    You do a concat ("+="), but I don't see "errors" defined anywhere. Is it
    global? If not, you need
    var errors = "";
    at the beginning of this function.

    > } else {
    > errors += "[ " + str + " ] is een onjuist emailadres.\n";
    > ////////////////////////////////////////////// THIS IS SUPPOSED TO BE A
    > PROBLEM


    See above about the variable "errors".


    --
    --
    ~kaeli~
    Synonym: the word you use in place of a word you can't
    spell.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Aug 5, 2004
    #2
    1. Advertising

  3. Laiverd.COM

    Laiverd.COM Guest

    Yes that occured to me, and that's why I indicated the trouble line. Sorry
    if that wasn't clear enough. I put up the page here:

    http://home.hccnet.nl/john.mulder/flash/temp/forms/example_form.html

    John

    --
    ----------------------------------------------------------------------------
    -----------
    RESOURCES
    http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
    ----------------------------------------------------------------------------
    -----------
    TUTORIALS at
    www.laiverd.com
    Flash & PHP Emailform
    Using textfiles in Flash
    ----------------------------------------------------------------------------
    -----------
     
    Laiverd.COM, Aug 5, 2004
    #3
  4. Laiverd.COM

    Laiverd.COM Guest

    Well it did work untill I did not hardcode the names of the required fields
    in javascript but instead created an array on the fly, like this

    var requiredFields = new Array();
    // get values for required fields from the form
    var required = document.forms.contact.required.value;
    requiredFields = required.split(",");
    var errors = "";

    As you see errors is initialised, and checkEmail() is called from a function
    checkForm();

    Just in case someone is willing to dive into all the code, here it is:

    http://home.hccnet.nl/john.mulder/flash/temp/forms/example_form.html

    Thanks again.

    John

    --
    ----------------------------------------------------------------------------
    -----------
    RESOURCES
    http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
    ----------------------------------------------------------------------------
    -----------
    TUTORIALS at
    www.laiverd.com
    Flash & PHP Emailform
    Using textfiles in Flash
    ----------------------------------------------------------------------------
    -----------
     
    Laiverd.COM, Aug 5, 2004
    #4
  5. Laiverd.COM

    Laiverd.COM Guest

    Re: Object expected; can't find it. Need another pair of eyes [solved]

    Okay found out that it was a scope problem. I declared errors inside the function checkForm(), so it was local to that function and
    not available in checkEmail().

    Thanks for your time.

    John

    --
    ---------------------------------------------------------------------------------------
    RESOURCES
    http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
    ---------------------------------------------------------------------------------------
    TUTORIALS at
    www.laiverd.com
    Flash & PHP Emailform
    Using textfiles in Flash
    ---------------------------------------------------------------------------------------
     
    Laiverd.COM, Aug 5, 2004
    #5
  6. Laiverd.COM wrote:
    > Well it did work untill I did not hardcode the names of the required
    > fields in javascript but instead created an array on the fly, like
    > this
    >
    > var requiredFields = new Array();
    > // get values for required fields from the form
    > var required = document.forms.contact.required.value;
    > requiredFields = required.split(",");
    > var errors = "";
    >
    > As you see errors is initialised, and checkEmail() is
    > called from a function checkForm();


    No, Kaeli was spot-on. You are defining - errors - as a local variable
    in the - checkForm - function so it is not global, and then you are
    using it in the - checkEmail - function as if it was global.

    There are some other odd things in your code. You are using -
    onSubmit="return checkForm(this);" - so the - checkForm - function is
    being passed a reference to the function element as a parameter, but
    instead of using it, it is repeatedly looking up the form in the -
    documents.forms collection.

    And building RegExp objects with the constructor using string literal
    constants whenever you call the - checkEmail - function is a bit
    over-the-top.

    Richard.
     
    Richard Cornford, Aug 5, 2004
    #6
  7. Laiverd.COM

    Laiverd.COM Guest

    Thanks for the tips Andrew. It is appreciated.

    John

    --
    ---------------------------------------------------------------------------------------
    RESOURCES
    http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
    ---------------------------------------------------------------------------------------
    TUTORIALS at
    www.laiverd.com
    Flash & PHP Emailform
    Using textfiles in Flash
    ---------------------------------------------------------------------------------------
     
    Laiverd.COM, Aug 5, 2004
    #7
  8. Laiverd.COM

    Laiverd.COM Guest

    Richard,
    Thanks for all your remarks. I'll definitely have a look into it.

    John

    --
    ---------------------------------------------------------------------------------------
    RESOURCES
    http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
    ---------------------------------------------------------------------------------------
    TUTORIALS at
    www.laiverd.com
    Flash & PHP Emailform
    Using textfiles in Flash
    ---------------------------------------------------------------------------------------
     
    Laiverd.COM, Aug 5, 2004
    #8
  9. Laiverd.COM

    Lee Guest

    Richard Cornford said:

    >There are some other odd things in your code. You are using -
    >onSubmit="return checkForm(this);" - so the - checkForm - function is
    >being passed a reference to the function element as a parameter, but


    Quick! Somebody think of a clever line about confusing "form" and "function".
     
    Lee, Aug 5, 2004
    #9
  10. Lee wrote:
    > Richard Cornford said:

    <snip>
    >>... passed a reference to the function element as a parameter,

    <snip>
    > Quick! Somebody think of a clever line about confusing
    > "form" and "function".


    <grin class="sheepish"/>

    Isn't it a modernist aesthetic principle that form should follow
    function?

    Richard.
     
    Richard Cornford, Aug 5, 2004
    #10
    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. darrel
    Replies:
    0
    Views:
    363
    darrel
    Jun 21, 2004
  2. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: need second pair of eyes: databinder.eval problem

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    445
    darrel
    Jun 21, 2004
  3. DaLoverhino

    J2ee: need another pair of eyes.

    DaLoverhino, Nov 22, 2005, in forum: Java
    Replies:
    1
    Views:
    405
    HalcyonWild
    Nov 22, 2005
  4. =?Utf-8?B?cm9kY2hhcg==?=

    another pair of eyes...

    =?Utf-8?B?cm9kY2hhcg==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    348
    =?Utf-8?B?cm9kY2hhcg==?=
    Jul 12, 2006
  5. Luminousc
    Replies:
    4
    Views:
    1,110
    Erwin Moller
    Mar 25, 2005
Loading...

Share This Page