Asked  7 Months ago    Answers:  5   Viewed   33 times

I just want to know how can I display a javascript variable into html?

Below is my php code:

var duration = <? echo $postduration; ?>;

(The variable above uses php to retrieve a php variable)

Thank you



Make your code more concise with jQuery:

(1) Add this in your <head>:

<script src=""></script>

(2) Create an element where you want the variable to be displayed, and give it an ID, e.g.:

<span id="printHere"></span>

(3) Add this in your JavaScript:

var duration="<?php echo $postduration ?>";

For your PHP, try the following two options:



<?php echo $postduration; ?>
Wednesday, March 31, 2021
answered 7 Months ago

If both of your function are residing in the same class you can call a function inside another function using $this as pointed in other answers

class myclass{

public $var1 = 121;
    public function foo($postid){
        echo $postid;
    public function bar(){
$objectmyclass = new myclass();


class myclass{

public $var1 = 122;
    public function foo($postid){
        echo $postid;
    public function bar($postid){
$objectmyclass = new myclass();

both ways you will be able to execute the statements inside the function foo hope this helps

Wednesday, March 31, 2021
answered 7 Months ago

Why you are not using json_encode

 $data = array( );
 foreach (glob($queryglob) as $filename) $data[$filename] = array( 'caption' => '' );
<script type="text/javascript">
 var data = <?php echo json_encode( $data ); ?>

That is much more clever than building a string

Saturday, May 29, 2021
answered 5 Months ago

Based on your screenshot of Settings (Preferences on Mac) | Editor | Language Injections.

Please delete 3rd language injection rule from the bottom (the one for "div" -- that has "IDE" in Scope column).

That rule injects HTML into div tag which tells IDE to treat all other code (even PHP) inside such tag as HTML/plain text.

Thursday, August 5, 2021
answered 3 Months ago

A recent change in PHPMailer allows Debugoutput to be a closure, so you can make it do whatever you like, for example to collect all the debug output and emit it later:

$debug = '';
$mail->Debugoutput = function($str, $level) {
    $GLOBALS['debug'] .= "$level: $strn";
echo $debug;
Monday, August 16, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :