0

Below is my PHP MySQL Query and getting the last value result, I want to add 10 Javascript functions into my PHP page at end of page, however counting of variable works but I am not able to concat that value to function and other variable names.

Below is my code:

<script>
<?php 
 $brSql = "SELECT BRANCH_ID FROM `tb_um_client_branches` ORDER BY BRANCH_ID DESC LIMIT 1";
$brRset = mysql_query($brSql) or die('BRANCH LAST ID QUERY FAIL: '.mysql_error());
$brRID = mysql_fetch_row($brRset);


for($i = 0; $i < 10; $i++){

?>

cnter = (<?php echo $brRID[0]; ?> + <?php echo $i; ?>)

function getChecked_+cnter(){

var nodes+cnter = $('#tt_+cnter').tree('getChecked');

//var nodes = $('#tt').tree(data-options="method:'get',animate:true,checkbox:true");
var s_+cnter = '';
for(var i_+cnter=0; i_+cnter<nodes_+cnter.length; i_+cnter++){
    if (s_+cnter != '') s_+cnter += ',';
    s_+cnter += nodes_+cnter[i_+cnter].id + ' ' + nodes_+cnter[i_+cnter].text;
}

//$('#OLD_BRANCH_FILTERS_+cnter').value = s_+cnter;
$('#OLD_BRANCH_FILTERS_'+cnter).attr('value', s_+cnter);

//alert(s_+cnter);
}

console.log(cnter);

<?php 
}
?>
</script>

Below is error, I am getting:

SyntaxError: missing ( before formal parameters 
function getChecked_[cnter](){

Earliest help will be appreciated.

Thanks in advance !

Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104
  • function names and variable names cannot contains `+` in them.. change `nodes+cnter` to `nodes_cnter` and other variables too – Arun P Johny Nov 07 '13 at 08:45

1 Answers1

0

This syntax

function getChecked_+cnter(){

is not valid.

You should use something of that

this["getChecked_"+cnter] = function() {

Important: there is a little difference with this declaration.

Community
  • 1
  • 1
Luca Rainone
  • 16,138
  • 2
  • 38
  • 52