Javascript – echo a php variable into innerhtml

innerhtmljavascriptjqueryMySQLPHP

I have a problem in my code, I want to put $meaning variable into innerhtml of my di,here is my code:
searchinput.php:

<form action = "search.php" method = "post">
    <input name="word" id="word" type="text" maxlength="255" />
    <label for="word">word:</label></br></br>
    <input type="submit" value="search" />

</form>
<div id = "meaning"> </div>

search.php:

<?php
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db("project",$db);
    $word = isset($_POST["word"]) ? $_POST["word"] : "";
    $result = mysql_query("select meaning from vocabulary where word = '$word'");
    $fetchmeaning = mysql_fetch_array($result); 
    $meaning = $fetchmeaning['meaning'];
?>

now I want to have this:

document.getElementById('meaning').innerhtml = $meaning; !!!!

how can I impelemt this?

Best Answer

Yes. Start a script tag after the definition of $meaning and put the below code in it. Like.

document.getElementById('meaning').innerHTML = "<?PHP echo $meaning; ?>" ;

Also Can't you think of directly echo ing the value of $meaning inside the div without even using javascript? like

<div id = "meaning"><?PHP echo $meaning; ?></div>

You can also use the short form <?=$meaning?>.