This is working, after all it's a syntax error, but I was wondering how could one do this so that the syntax is proper.
The code below is part of a script that is preparing variables to be sent on a Ajax call, so depending on the scope the corresponding variable should be passed on to Ajax.
Problem, from javascript perspective, it seems, is that only the php variable for each scope is defined.
I would think that it would not try at all to parse if the else if condition is not met, but apparently that is not the case. The php variable $scope is always defined.
Both firebug and Chrome developer tool are throwing the error:
var scope_var = <br />
<b>Notice</b>: Undefined variable: brand in <b>/Applications/MAMP/htdocs/my_site/my_script.php</b> on line <b>1049</b><br />null;
Thanks
var scope = <?php echo json_encode($scope) ;?>;
if (scope == 'all') {var scope_var = 'all';}
else if (scope == 'brands') {var scope_var = <?php echo json_encode($brand) ;?>;}
else if (scope == 'cities') {var scope_var = <?php echo json_encode($city) ;?>;}
else if (scope == 'models') {var scope_var = <?php echo json_encode($model) ;?>;}
else if (scope == 'prange') {var scope_var = <?php echo json_encode($used_prange_low) . '|' . json_encode($used_prange_high) ;?>;}