SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error undifined array

    OK I am noobie to JS and have receive an error i do not understand of array undifined line 3.

    This is simply apart of a script to validate a form I know this is going to turn out to be something rookie, but I am a bit lost, any help would be much appriciated.

    Code:
    /* define a function to be called later by an onclick comand saving the submit comand for a php script later */
    function notEmpty(){

    // setsup an array with the required fields listed in it.
    // this is the line I beleave that the error is refearing to.
    var Element=new array("mytext","mytext1","mytext2");

    // Sets up an array with to hold the required feilds that are empty.
    var BadData=new array();

    // Sets an integer so a for loop can read through the Elements array.
    var i=0;

    /* sets up an integer so the BadData array can be assigned empty required feilds from the Elements array. */
    var v=0;

    //runs through the arrays enering values into BadData array.
    while (i<=2)
    {
    var myTextField = document.getElementById("Element[i]");
    if(myTextField.value == "")
    {
    BadData[v]=Ellement[i];
    i++;
    v++;
    }
    else
    {
    i++;
    }
    }

    /* this part should display the fields that have not been field in*/
    var BDCount=BadData.length;
    if (BDCount>=1)
    {
    document.write("please fill in the following feilds");
    for (x in BadData)
    {
    document.write(BadData[x] + "<br />");
    }
    }
    else
    {
    //this is just for testing reasons.
    alert("the form is valid");
    }
    }


    I beleave the logich here should be sound but I have been wrong in the past. any help would be appriciated.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try changing

    Code JavaScript:
    var BadData=new array();
    to

    Code JavaScript:
    var BadData=new Array();

  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awsome that got rid of that error, thanx SGT.

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    No problem


Bookmarks

Posting Permissions

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