-1

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> ';
   }
   ?>
6
  • 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 Commented Sep 29, 2017 at 7:06
  • Hello Rory i did this with php if statement. without php it's running well Commented Sep 29, 2017 at 7:07
  • 1
    Exactly - why put it in PHP at all? Commented Sep 29, 2017 at 7:07
  • Because i check out this link :- stackoverflow.com/questions/3057317/… in this run JavaScript through PHP. in if statement. Commented Sep 29, 2017 at 7:09
  • That doesn't make it a good idea. In fact, I'd say it's a really, really bad idea. Commented Sep 29, 2017 at 7:11

1 Answer 1

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 }
 ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome work like a charm. Exactly what i want Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.