Reputation: 51
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?
Upvotes: 3
Views: 27896
Reputation: 2079
<div id="errorMessage"></div>
<?php
if (isset($_GET['q'])) {
echo '<script type="text/javascript">
document.getElementById("errorMessage").innerHTML = "User name or Password is incorrect";
</script>';
}
?>
Upvotes: 1
Reputation: 27845
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?>
.
Upvotes: 8