0

I have a php page home.php and in this I have a php variable $disableCreate = 'true'; . Please see the below code.

<?php

 ob_start();
 include_once("app_header.php");
 $disableVar = 'true';    

 //below code to show the home page template
 $htmlrenderObj = Htmlrender::getObj();          
 $template_path  = $htmlrenderObj->app_home_template_path."app_home.html";
 $template       = $htmlrenderObj->return_file_content($template_path);
 ob_end_flush(); 
 include_once("app_footer.php");
?>

Now in the java script section I'm trying to access that variable and assign it to java script variable.

<script>
 var xmlHttp = getAjaxObj();

 var myJsVar = "<?php echo $disableVar; ?>";
 var myJsVar2 = "<?php echo json_encode($disableVar); ?>";
 var myJsVar3 = "<?=$disableVar?>";
 var myJsVar4 = "$disableVar";

 console.log("$$$$$$$$ myJsVar is:"+myJsVar);
 console.log("$$$$$$$$ myJsVar is:"+myJsVar2);
 console.log("$$$$$$$$ myJsVar is:"+myJsVar3);
 console.log("$$$$$$$$ myJsVar is:"+myJsVar4);

</script>

I tried different ways to initialize my java script variable with php variable. But not get the desired output. Please see the below screenshot for reference.

enter image description here

Please help me.

user2636874
  • 889
  • 4
  • 15
  • 36
  • remove the php code form the quotes, for example: var myJsVar3 = =$disableVar; ?> and don't forget to close php line with ; – zippax Apr 14 '21 at 04:06
  • From the looks of it, "in the java script section" actually means "a separate javascript file which does not run through PHP". – mario Apr 14 '21 at 04:11
  • Hi zippax, I have edited my code as you suggested and getting Uncaught SyntaxError: Unexpected token '<' error. – user2636874 Apr 14 '21 at 04:46
  • Hi mario, it is not a separate javascript file. It is in the same html file under – user2636874 Apr 14 '21 at 04:47

0 Answers0