www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] em "'undefined' is null or not an object" only in IE

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    4

    resolved [RESOLVED] em "'undefined' is null or not an object" only in IE

    Hiya,

    I would like to ask your help regarding this damned error message that comes out only in Internet Explorer and makes impossible to submit the form.

    The javascript code is:

    // JavaScript Document

    function checkForm() {
    var cname,
    cspouse, cemail, chphone, ccellular, caddress, ccity, cstate, czip, cpets, cvolunteer, cadditional;

    with(window.document.volApplForm)
    {
    cname = Name;
    cspouse = Spouse;
    cemail = Email;
    chphone = HomePhone;
    ccellular = Cellular;
    caddress = Address;
    ccity = City;
    cstate = State;
    czip = Zip;
    cpets = Pets;
    cvolunteer = Volunteer;
    cadditional = Additional; }

    var ALERT_TITLE = "Oops!";
    var ALERT_BUTTON_TEXT = "Close";

    if(document.getElementById) {
    window.alert = function(txt) {
    createCustomAlert(txt);
    }
    }

    function createCustomAlert(txt) {
    d = document;

    if(d.getElementById("modalContainer")) return;

    mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
    mObj.id = "modalContainer";

    mObj.style.height = document.documentElement.scrollHeight + "px";

    alertObj = mObj.appendChild(d.createElement("div"));
    alertObj.id = "alertBox";

    if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";

    alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";


    h1 = alertObj.appendChild(d.createElement("h1"));
    h1.appendChild(d.createTextNode(ALERT_TITLE));


    msg = alertObj.appendChild(d.createElement("p"));
    msg.innerHTML = txt;


    btn = alertObj.appendChild(d.createElement("a"));
    btn.id = "closeBtn";
    btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
    btn.href = "#";

    btn.onclick = function() { removeCustomAlert();return false; }
    }




    if(trim(cname.value) == '')
    {
    alert('Please enter your name');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cname.focus();}
    return false;
    }
    else if(trim(cemail.value) == '')
    {
    alert('Please enter your email');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cemail.focus();}
    return false;
    }
    else if(!isEmail(trim(cemail.value)))
    {
    alert('Email address is not valid');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cemail.focus();}
    return false;
    }


    else if(trim(chphone.value) == '')
    {
    alert('Please enter your valid phone number');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); chphone.focus();}
    return false;
    }
    else if(trim(ccellular.value) == '')
    {
    alert('Please enter valid cell phone number');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); ccellular.focus();}
    return false;
    }
    else if(trim(caddress.value) == '')
    {
    alert('Please enter your valid address');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); caddress.focus();}
    return false;
    }
    else if(trim(ccity.value) == '')
    {
    alert('Please enter your city');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); ccity.focus();}
    return false;
    }
    else if(trim(cstate.value) == '')
    {
    alert('Please enter valid state name');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cstate.focus();}
    return false;
    }
    else if(trim(czip.value) == '')
    {
    alert('Please enter valid zip code');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); czip.focus();}
    return false;
    }

    else if(trim(cvolunteer.value) == '')
    {
    alert('Please fill in all fields');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cvolunteer.focus();}
    return false;
    }

    else if(trim(cadditional.value) == '')
    {
    alert('Please fill in all fields');
    function removeCustomAlert() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer")); cadditional.focus();}
    return false;
    }
    else
    {
    cname.value = trim(cname.value);
    cspouse.value = trim(cspouse.value);
    cemail.value = trim(cemail.value);
    chphone.value = trim(chphone.value);
    ccellular.value = trim(ccellular.value);
    caddress.value = trim(caddress.value);
    ccity.value = trim(ccity.value);
    cstate.value = trim(cstate.value);
    czip.value = trim(czip.value);
    cpets.value = trim(cpets.value);
    cvolunteer.value = trim(cvolunteer.value);
    cadditional.value = trim(cadditional.value);
    return true;
    }
    }

    function trim(str)
    {
    return str.replace(/^\s+|\s+$/g,'');
    }



    function isEmail(str)
    {
    var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn |bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk| dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs |gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr| kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum |mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr |pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf |tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;

    return regex.test(str);
    }


    And when trying to submit the form, I get the error message:

    Line: 177
    Character: 4
    Code: 0
    Error Message: 'undefined' is null or not an object
    URL: https://localhost/ruff/scripts/validationVol.js

    Do you have an idea what could be the problem? As I checked line 177, it seems to be OK. I checked the web, but didn't find anything related to this message in a situation like this.

    Thanks in advance for your comments.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Line 177 is what?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Mar 2010
    Posts
    4
    Quote Originally Posted by Fang View Post
    Line 177 is what?
    Eh, that's weird. :I
    So, line 177 is:
    Code:
    return str.replace(/^\s+|\s+$/g,'');
    , in the trim function.

    I got a doubt that maybe there's a problem with the regular expression, but it also seems to be OK. At least to me.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Check which trim call fails. Make sure the element it uses has a value attribute.
    Eh, that's weird. :I
    So, line 177 is:
    No line numbers and the script is 167 lines long ...
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Mar 2010
    Posts
    4
    Quote Originally Posted by Fang View Post
    Check which trim call fails. Make sure the element it uses has a value attribute.
    No line numbers and the script is 167 lines long ...
    Thanks, Fang!! You're right, there were two values undefined. Corrected, now the form works fine.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles