Dvir Levy
Dvir Levy

Reputation: 8108

Uncaught SyntaxError: Unexpected identifier

hello im am getting JS error :

 Uncaught SyntaxError: Unexpected identifier

here

<script type="text/javascript">
var cur_level = 1;
var ids_arr = new Array(<?php echo $max_level?>);
var im_here = new Array(<?php echo $max_level?>);
ids_arr[0] = 1;
im_here[0] = "|";
function displayData(id, level, used, title)
{
if(used){
    choice = document.getElementById('divv'+id).innerHTML;
    document.getElementById('test_div').innerHTML = choice;

} else {
    document.getElementById('test_div').innerHTML = ' No lerning paths to show.';
    updateLinksDiv(id, level, title);

  }
}

function updateLinksDiv(id, level, title)
{
var links_div_info = document.getElementById('links_parent_'+id);
var tmpHTML = '';
var here = '';

for(i=0;i<level;i++){
    here+= '->'+im_here[i];
    links_div_info = document.getElementById('links_parent_'+ids_arr[i]);
    tmpHTML += '<div id="divl_'+links_div_info.id+'">'+links_div_info.innerHTML+'</div>';
}
links_div_info = document.getElementById('links_parent_'+id);
tmpHTML += '<div id="divl_'+links_div_info.id+'">'+links_div_info.innerHTML+'</div>';

document.getElementById('links').innerHTML = tmpHTML;
ids_arr[i] = id;
im_here[i] = title;
}

</script>


<script type="text/javascript">
    window.onload=updateLinksDiv(1 , 0 , "|" ) ;
</script>

the functions are suppose to create an "expanding" that opens up with levels and everything was working fine untill i added the "title" and i started getting the error. the error points me to the last and i just cant find the error... i try to call displayData like this

onclick="displayData('.$cat->id.','.$cat->level.',0,'.$cat->title.')"

any suggestions for what i'm not seeing.?

thank you

Upvotes: 7

Views: 17892

Answers (1)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201558

In your comment you say that displayData(26,1,0,כיתה ג) is generated. This explains the symptoms, as here the last parameter contains a space in addition to Hebrew letters, so the JavaScript intepreter sees it as two identifiers separated by a space, and the identifiers are probably undefined. Google Chrome gives the error message you describe, whereas Firefox and IE say, more enigmatically, “missing ) after argument list.”

Apparently the generated code is supposed to have the last parameter in quotation marks, i.e. 'כיתה ג'. You need to modify the generation to contain them.

Upvotes: 8

Related Questions