0

PLease help me with this code

<?php
if (!empty($this->product->customfieldsSorted['youtube'])) {
    $this->position = 'youtube';
    echo '<button class="shop_tablinks tab2"  onclick='"openSpecs(event, 'Specs3')"' >';
    echo JText::_('Video'); 
    echo '</button>';
} // Product Custom ontop end
?>

It seems I don't wrote ok the

onclick='"openSpecs(event, 'Specs3')"' >'
Neodan
  • 5,154
  • 2
  • 27
  • 38
  • 2
    Whats your problem/Question? You didnt explain anything. – AutoTester213 Sep 12 '17 at 08:17
  • Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – crazyloonybin Sep 12 '17 at 08:17

2 Answers2

5

Replace you code with below:

<?php  if (!empty($this->product->customfieldsSorted['youtube'])) {
        $this->position = 'youtube';
        echo '<button class="shop_tablinks tab2"  onclick="openSpecs(event, \'Specs3\')">';
        echo JText::_('Video'); 
       echo '</button>';
   } // Product Custom ontop end
    ?>

Need to use escape operator for '' if you want to use in html code while echoing as you are echoing with ''. So in HTml code its taking it as concat operator.

Naincy
  • 2,953
  • 1
  • 12
  • 21
2

Change your line

echo '<button class="shop_tablinks tab2"  onclick='"openSpecs(event, 'Specs3')"' >';

to

echo '<button class="shop_tablinks tab2"  onclick="openSpecs(event, \'Specs3\')" >';

final code:

if (!empty($this->product->customfieldsSorted['youtube'])) {
    $this->position = 'youtube';
    echo '<button class="shop_tablinks tab2"  onclick="openSpecs(event, \'Specs3\')" >';
    echo JText::_('Video'); 
    echo '</button>';
}
Jigar Shah
  • 6,143
  • 2
  • 28
  • 41