Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 827
Dvir Levy Avatar asked Jan 08 '12 12:01

Dvir Levy


People also ask

How do I fix uncaught SyntaxError unexpected identifier?

To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.

What is uncaught syntax error?

Last reviewed in August 2021. The error Uncaught SyntaxError: Unexpected token < is most commonly caused by your site's code referring to an asset that is no longer available. Most commonly, this is due to a filename change in assets generated during your build.

What does it mean by uncaught SyntaxError unexpected token?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.


1 Answers

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.

like image 163
Jukka K. Korpela Avatar answered Sep 19 '22 02:09

Jukka K. Korpela