php - Function not called via javascript in href -


I have used a code that I found in the web and then changed a bit:

  & lt; Script type = "text / javascript" & gt; Var Food List = []; Function addToFood (addFood) {addFood}; //foodList.push(addFood); // (i = 0; i & lt; foodList.length; i ++) {// var newFood = "& lt; ARR = '#' onClick = 'removeRecord (" + i + ");' & Gt; X & lt; / a & gt; "+ Food List [i] +" + "
"; //}; //document.getElementById('foods').innerHTML + newfood; } & Lt; / Script & gt;

At this time I want to alert the parameter on addToFood. Function should be called:

  echo "& lt; a href = 'javascript: addToFood (". $ Zeile1 [' TITLE ']. ");' Class = 'band head' & gt; add & lt; / a & gt; ";  

This row shows that I have javascript in JavaScript with & lt; A & gt; How to add. PHP presents the correct line, but addToFood never calls.

Look at the online demo: Maybe it could help you and then me. I get the error through Google Chrome: Unwanted syntax error: unexpected identifier but unidentified identifier is not yet identified.

Thank you

You enter $ zeile1 ['TITLE' ] is required to wrap, such as:

  echo "& lt; a href = 'javascript: addToFood (\" ". $ Zeile1 [' TITLE ']." \ "); ' Class = 'band head' & gt; add & lt; / a & gt; ";  

You can see that after the quoted brackets \ " after quoted brackets, and before the end, in the JS call, otherwise it will try. / P>

Why are you saved? That's because you resonated with: PHP. If I could not escape the quote, then PHP would explain it to the string that was ending, which is not what we want I want to put quotation marks inline code.


Comments