I have some PHP
which outputs JavaScript
. I need to set the id
dynamically. The following code breaks on the 3rd line because of the use of the i
variable. This I expect to be a simple problem with the quotation marks but I could be wrong.
$html .='$("#add").click(function (e) {';
$html .= 'var i=0;';
//Append a new row of code to the "#items" div
$html .='$("#items").append(\'<div><input name=\"input[]\" type=\"text\" id=\"itin_form_'+i+'\" /><button class=\"delete\">Delete</button></div>\'); i++; });';
Can anyone see why this code fails?