Javascript For-Each Loop Syntax Help
- by radrew
Hey guys, I've got a complex block of PHP/Javascript that isn't functioning. I'm trying to manipulate a form that contains 4 dropdown select lists. Each dropdown is dependent upon what was selected in the one above it. I apologize for the huge amount of code, but I was hoping someone might be able to spot a syntax error or something else simple that I'm missing.
The form in question is located in the right sidebar of the following site: http://www.buyautocovers.com
$Manufacturer_array[] = array('id' => 'all', 'text' => $this->__('Choose Make'));
$Model_array[] = array('id' = 'all', 'text' = $this-('Choose Model'));
$Number_array[] = array('id' = 'all', 'text' = $this-('Choose Year'));
$Body_array[] = array('id' = 'all', 'text' = $this-__('Choose Body Type'));
$javascript = '
//
var a = new Array();
var b = new Array();
var c = new Array();
var d = new Array();';
$M_a = array();
foreach ($rows as $r) {
if (!isset($M_a [$r['manufacturer']]))
$Manufacturer_array[] = array('id' = $r['manufacturer'], 'text' = $r['manufacturer']);
$M_a [$r['manufacturer']][$r['model']][$r['number']][$r['body']] = 1;
}
$i = 0;
foreach ($M_a as $k =$v){
$javascript .= 'a['.$i.']="'.$k.'";b['.$i.'];c['.$i.'];=new Array(';
$ii = 0;
$s = '';
foreach ($M_a[$k] as $kk =$vv){
$javascript .= ($ii != 0 ? ',' : '').'"'.$kk.'"';
$ss = '';
$iii = 0;
foreach ($M_a[$k][$kk] as $kkk = $vvv){
$javascript .= ($iii != 0 ? ',' : '').'"'.$kkk.'"';
$sss = '';
$iiii = 0;
foreach ($M_a[$k][$kk][$kkk] as $kkkk = $vvvv){
$sss .= ($iiii != 0 ? ',' : '').'"'.$kkkk.'"';
$iiii++;
}
$ss .= 'd['.$i.']['.$ii.']['.$iii.']=new Array('.$sss.');';
$iii++;
}
$s .= 'd['.$i.']['.$ii.']=new Array('.$ss.');';
$ii++;
}
$javascript .= ');d['.$i.']=new Array();'.$s;
$i++;
}
$javascript .= '
function pop_model(){
var o ="' . $this-('Choose Model') . '";
var sv = $(\'mmn_manufacturer\').value;
if(sv != "all"){
var v = a.length;
while(v--) if(sv == a[v]) break;
for(var i = 0; i < b[v].length; i++)
o+=""+b[v][i]+"";
}
o+="";
$(\'model_select\').innerHTML= o;
$(\'number_select\').innerHTML= "' . $this-('Choose Year') . '";
}
function pop_number(){
var o ="' . $this-('Choose Year') . '";
var sv = $(\'mmn_manufacturer\').value;
if(sv != "all"){
var v = a.length;
while(v--) if(sv == a[v]) break;
var sv2 = $(\'mmn_model\').value;
if(sv2 != "all"){
var v2 = b[v].length;
while(v2--) if(sv2 == b[v][v2]) break;
for(var i = 0; i < c[v][v2].length; i++)
o+=""+c[v][v2][i]+"";
}
}
o+="";
$(\'number_select\').innerHTML= o;
$(\'body_select\').innerHTML= "' . $this-('Choose Body Type') . '";
}
function pop_body(){
var o ="' . $this-__('Choose Body Type') . '";
var sv = $(\'mmn_manufacturer\').value;
if(sv != "all"){
var v = a.length;
while(v--) if(sv == a[v]) break;
var sv2 = $(\'mmn_model\').value;
if(sv2 != "all"){
var v2 = b[v].length;
while(v2--) if(sv2 == b[v][v2]) break;
var sv3 = $(\'mmn_number\').value;
if(sv3 != "all"){
var v3 = c[v].length;
while(v3--) if(sv3 == b[v]c[v2][v3]) break;
for(var i = 0; i < d[v]c[v2][v3].length; i++)
o+=""+d[v]c[v2][v3][i]+"";
}
}
}
o+="";
$(\'number_select\').innerHTML= o;
}
//]]
';
$expire = time()+60*60*24*90;
if (isset($_GET['Manufacturer'])){
setcookie("Manufacturer_selected", $_GET['Manufacturer'], $expire,'/');
if ($_GET['Manufacturer'] != 'all')
$Manufacturer_selected_var = $_GET['Manufacturer'];
} elseif (isset($_COOKIE['Manufacturer_selected']) && $_COOKIE['Manufacturer_selected'] != 'all')
$Manufacturer_selected_var = $_COOKIE['Manufacturer_selected'];
if (isset($_GET['Model'])){
setcookie("Model_selected", $_GET['Model'], $expire,'/');
if ($_GET['Model'] != 'all')
$Model_selected_var = $_GET['Model'];
} elseif (isset($_COOKIE['Model_selected']) && $_COOKIE['Model_selected'] != 'all')
$Model_selected_var = $_COOKIE['Model_selected'];
if (isset($_GET['Number'])){
setcookie("Number_selected", $_GET['Number'], $expire,'/');
if ($_GET['Number'] != 'all')
$Number_selected_var = $_GET['Number'];
} elseif (isset($_COOKIE['Number_selected']) && $_COOKIE['Number_selected'] != 'all')
$Number_selected_var = $_COOKIE['Number_selected'];
if (isset($_GET['Body'])){
setcookie("Body_selected", $_GET['Body'], $expire,'/');
if ($_GET['Body'] != 'all')
$Body_selected_var = $_GET['Body'];
} elseif (isset($_COOKIE['Body_selected']) && $_COOKIE['Body_selected'] != 'all')
$Body_selected_var = $_COOKIE['Body_selected'];
if (isset($Manufacturer_selected_var) && isset($M_a[$Manufacturer_selected_var]))
foreach ($M_a[$Manufacturer_selected_var] as $k => $v)
$Model_array[] = array('id' = $k, 'text' = $k);
if (isset($Manufacturer_selected_var) && isset($Model_selected_var) && isset($M_a[$Manufacturer_selected_var][$Model_selected_var]))
foreach ($M_a[$Manufacturer_selected_var][$Model_selected_var] as $k = $v)
$Number_array[] = array('id' = $k, 'text' = $k);
if (isset($Manufacturer_selected_var) && isset($Model_selected_var) && isset($Number_selected_var) && isset($M_a[$Manufacturer_selected_var][$Model_selected_var][$Number_selected_var]))
foreach ($M_a[$Manufacturer_selected_var][$Model_selected_var][$Number_selected_var] as $k = $v)
$Body_array[] = array('id' = $k, 'text' = $k);
echo $javascript;