Ronak Patel Ronak Patel - 1 year ago 147
PHP Question

ReferenceError: array is not defined

I have loop in

with javascript: First array is printing on console output. But, in second element of array I am getting this error:

ReferenceError: array is not defined

<?php foreach($job_requirements_names as $jrn){ ?>
<div class="col-md-12 form-group">
<label class="control-label label-top" for="requirement_<?=strtolower($jrn['name'])?>"><?=$jrn['name']?></label>
$query = new QUERY(array('TABLE'=>$table_name, 'KEY'=>array('name'=>$jrn['name']), 'ASC'=>'n_option'));
$options = $query->fetchAll();
$id = "requirement_".strtolower($jrn['name']);
// For countries:
var data = '<?php echo json_encode($options);?>';
data = JSON.parse(data);
data = (v) { return {id:, text: v.n_option}; });

multiple: true,
data: data
}).select2('data', array());

<input id='requirement_<?=strtolower($jrn['name'])?>' name="requirement_<?=strtolower($jrn['name'])?>" class="col-md-12"/>
<?php } ?>

As you can see in
array is already defined.

Answer Source

You should to use Array() instead of array() (Not exist) since JS is a case sensitive language, or simply use [], so it will be :

.select2('data', new Array());
.select2('data', []);

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download