Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Error: "ReferenceError: array is not defined"

I want to make a JavaScript array and pass it to another page in php via post request I get an error in firebug:

ReferenceError: array is not defined

Here's the code:

$(document).ready(function(){
    var data = new array();               // this line throws the error
    // Handle Submiting form data
    $("#btnSumbit").click(function (){

        $('#tblCriteria input[type=text]').each(
            function(){
                data[this.id] = this.value;
            }
        );  

This code inside cakePHP view.

like image 547
UserNew Avatar asked Jan 12 '13 13:01

UserNew


2 Answers

JavaScript is case sensitive, so to create a new array write Array with a capital letter:

var data = new Array();

However you may always use a short version:

var data = [];
like image 180
VisioN Avatar answered Oct 30 '22 14:10

VisioN


You need to declare Array above before it was used checking case sensitive name

 var arrayName = []; //  1
          or
 var arrayName = new Array(); //  2 
like image 30
Vinay Kaithwas Avatar answered Oct 30 '22 14:10

Vinay Kaithwas