0

When I run it without PHP then this running well.

      <?php 

       $it="$getuser[active]"; if($it==1)
       { echo '<script type="text/javascript">';
       echo ' $(document).ready(function () {
       var unique_id = $.gritter.add({
        // (string | mandatory) the heading of the notification
        title: "Welcome to my website!",
        // (string | mandatory) the text inside the notification
        text: "Activate Your Account Now!!<a href="active.php" target="_blank" style="color:#ffd777">Click Here</a>.",
        // (string | optional) the image to display on the left
        image: "img.jpg",
        // (bool | optional) if you want it to fade out on its own or just 
        sit there
        sticky: true,
        // (int | optional) the time you want it to be alive for before 
        fading out
        time: "",
        // (string | optional) the class name you want to apply to that specific message
        class_name: "my-sticky-class"
    });';

       echo '  return false;
    });';
    echo '</script> ';
   }
   ?>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    Why are you doing this? The code is an unreadable mess. Just output the JS directly without using `echo`. Also 'uncaught syntax error` is half the message. The other half tells you *exactly* what the error is, and what line it's on – Rory McCrossan Sep 29 '17 at 07:06
  • Hello Rory i did this with php if statement. without php it's running well –  Sep 29 '17 at 07:07
  • 1
    Exactly - why put it in PHP at all? – Rory McCrossan Sep 29 '17 at 07:07
  • Because i check out this link :- https://stackoverflow.com/questions/3057317/run-a-javascript-function-from-a-php-if-statement in this run JavaScript through PHP. in if statement. –  Sep 29 '17 at 07:09
  • That doesn't make it a good idea. In fact, I'd say it's a really, really bad idea. – Rory McCrossan Sep 29 '17 at 07:11
  • So how to do that. because this is the notification script popup i want to done in PHP script how to do that @RoryMcCrossan –  Sep 29 '17 at 07:14

1 Answers1

1

You have to escape ". text: "Activate Your Account Now!!<a href="active.php" target="_blank" style="color:#ffd777">Click Here</a>.", this line will create issue also remove line break before "sit there" and "fading out"

<?php 
$it="$getuser[active]"; if($it==1)
{ 
     echo '<script type="text/javascript">';
     echo ' $(document).ready(function () {
     var unique_id = $.gritter.add({
      // (string | mandatory) the heading of the notification
      title: "Welcome to my website!",
      // (string | mandatory) the text inside the notification
      text: "Activate Your Account Now!!<a href=\"active.php\" target=\"_blank\" style=\"color:#ffd777\">Click Here</a>.",
      // (string | optional) the image to display on the left
      image: "img.jpg",
      // (bool | optional) if you want it to fade out on its own or just  sit there
      sticky: true,
      // (int | optional) the time you want it to be alive for before fading out
      time: "",
      // (string | optional) the class name you want to apply to that specific message
      class_name: "my-sticky-class"
  });';

     echo '  return false;
  });';
  echo '</script> ';
 }
 ?>

EDIT

You can skip php part also and just write script directly

<?php 
$it="$getuser[active]"; if($it==1)
{ ?>
    <script type="text/javascript">
     $(document).ready(function () {
     var unique_id = $.gritter.add({
      // (string | mandatory) the heading of the notification
      title: "Welcome to my website!",
      // (string | mandatory) the text inside the notification
      text: 'Activate Your Account Now!!<a href="active.php" target="_blank" style="color:#ffd777">Click Here</a>.',
      // (string | optional) the image to display on the left
      image: "img.jpg",
      // (bool | optional) if you want it to fade out on its own or just  sit there
      sticky: true,
      // (int | optional) the time you want it to be alive for before fading out
      time: "",
      // (string | optional) the class name you want to apply to that specific message
      class_name: "my-sticky-class"
  });

     return false;
  });
  </script>
 <?php }
 ?>
B. Desai
  • 16,414
  • 5
  • 26
  • 47