Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahr's avatar
Level 10

Uncaught SyntaxError: '' string literal contains an unescaped line break

I have an error in console

Uncaught SyntaxError: '' string literal contains an unescaped line break

'<ul>\n' +
'<?php for ($i = 1; $i < 31; $i++){
        echo '<li onclick="updateBasket('.$i.','+value['basketID'].')"><?= $i ?></li>';
    }
?>'+
'</ul>\n' +
0 likes
6 replies
s4muel's avatar

you mix up php and javascript here:

echo '<li onclick="updateBasket('.$i.','+value['basketID'].')"><?= $i ?></li>';

you are still in php context, when using <?= $i ?> the value['basketId'] has to be evaluated in JS? dont you have that basketId variable present in php?

//this just echoes out `value['basketId']`, but i am not sure it will work as you expect
echo '<li onclick="updateBasket(' . $i . ', value[\'basketID\'])">' . $i . '</li>'; 

//this should work when you have the `$basketId` in php
echo '<li onclick="updateBasket(' . $i . ', ' . $basketId . ')">' . $i . '</li>';

but i strongly suggest to refactor all of that code, you are in JS context printing HTML using PHP that prints HTML and JS 🤯

1 like
Sinnbeck's avatar

Please show the actual code instead of a copy/paste from the error.

s4muel's avatar
s4muel
Best Answer
Level 50

have you tried this?

echo '<li onclick="updateBasket(' . $i . ', value[\'basketID\'])">' . $i . '</li>'; 

i suggest at least switching from php to javascript when using the for loop

var tr = '<tr>\n' + 
//... +
'<ul>';

var i;
for (i = 1; i < 31; i++) {
  tr += '<li onclick="updateBasket(' + i + ', ' + value['basketID'] + ')">' + i + '</li>';
}
tr += '</ul>';

at least make this work and then try a find a totally different approach

1 like
kingzamzon's avatar

You can also use template laterals in javascript e.g

let cardAboutBusiness = `{{ $features->content }}`;
$("[design-business-about]").html(cardAboutBusiness)

Please or to participate in this conversation.