Skip to main content
added 55 characters in body
Source Link
Lodder
  • 26.9k
  • 3
  • 48
  • 94

Instantly see the issue here. What you basically doing is the following:

<?php    
    $var = 'foo';
    <?php echo $foo; ?>    
?>

You're using duplicate <?php tags which will cause issues.

Use the following instead

<?php
    $document = JFactory::getDocument();
    $variable = "test";
    
    $document->addScriptDeclaration('
        jQuery(document).ready(function () {
            var simple = "' . $variable . '";
            alert(simple);
        });
    ');
?>

You were also missing a closing single quote before the last bracket in your code which I've added for you.

Instantly see the issue here. What you basically doing is the following:

<?php    
    $var = 'foo';
    <?php echo $foo; ?>    
?>

You're using duplicate <?php tags which will cause issues.

Use the following instead

$document = JFactory::getDocument();
$variable = "test";

$document->addScriptDeclaration('
    jQuery(document).ready(function () {
        var simple = "' . $variable . '";
        alert(simple);
    });
');

Instantly see the issue here. What you basically doing is the following:

<?php    
    $var = 'foo';
    <?php echo $foo; ?>    
?>

You're using duplicate <?php tags which will cause issues.

Use the following instead

<?php
    $document = JFactory::getDocument();
    $variable = "test";
    
    $document->addScriptDeclaration('
        jQuery(document).ready(function () {
            var simple = "' . $variable . '";
            alert(simple);
        });
    ');
?>

You were also missing a closing single quote before the last bracket in your code which I've added for you.

Source Link
Lodder
  • 26.9k
  • 3
  • 48
  • 94

Instantly see the issue here. What you basically doing is the following:

<?php    
    $var = 'foo';
    <?php echo $foo; ?>    
?>

You're using duplicate <?php tags which will cause issues.

Use the following instead

$document = JFactory::getDocument();
$variable = "test";

$document->addScriptDeclaration('
    jQuery(document).ready(function () {
        var simple = "' . $variable . '";
        alert(simple);
    });
');