I have a problem with my PHP/JavaScript and accent. When I give a variable who contain an accent, the JavaScript’s console say : Uncaught SyntaxError Unexpected Identifier.
PHP:
foreach($credit as $k => $v)
{
$id = $credit[$k]->id_credit;
$nom = $credit[$k]->nom_credit;
$prix = $credit[$k]->prix_credit;
echo "<a onClick='modification(".$id.",".$nom.",".$prix.");'>" . Image::resize('images/credit/' . $credit[$k]->id_credit . "." . $credit[$k]->format_image_credit,100,100) . "</a>";
}
JavaScript:
function modification(id,nom,prix)
{
var div = document.getElementById('modifCredit').style.display = 'block';
alert(id + " " + nom + " " + prix);
}
Without $nom, all works. And If I replace :
$nom = $credit[$k]->nom_credit;
By :
$nom = "example";
I got :
Uncaught ReferenceError: example is not define.
I think your php code results in something like
which makes the javascript interpreter believe that “example” is the name of a variable. You need to enclose it in quotes so that javascript interprets it as a string.
I assume $id and $prix are always numbers, and numbers should not be quoted and will not appear as variable names to the javascript interpreter.
The reason why you get a different error message when $nom contains an accent is that a variable name with an accent is invalid, and the interpreter discovers the invalid identifier before it discovers that the variable is undefined.