如何使用php或jquery js将php变量添加到现有textarea?
Echo”<script> $(document).ready(function(){$(#id).text(‘Test’);});</Script>”;
但是我的文本区域没有任何显示。
<?php include 'dbconn.php';?><?php
echo '<textarea id="id" cols="43" rows="7"></textarea>';
$sqlbetweendate=('SELECT SUM(Pris) FROM bestallning WHERE Datum BETWEEN "'.$dateFrom.'" AND"'.$dateTo.'"');
$result = mysqli_query($read_info,$sqlbetweendate);
while ($row =mysqli_fetch_array($result)) {
$test = $row['SUM(Pris)'];
}
Echo” <script> $(document).ready(function(){ $('#id').text('Test');});</script>”;}?>
<?php include 'footer.php';?>
jquery的链接在我的页脚文件中。页面已完全加载。
答案 0 :(得分:0)
对此进行更改
Echo” <script> $(document).ready(function(){ $('#id').text('Test');});</script>”;}?>
对此
Echo"<script>document.getElementById('id').value = '$test';</script>";
我已经尝试过并且工作正常。问题是您没有在任何地方使用定义的 $ test 。
答案 1 :(得分:0)
确保已设置 $ dateTo 和 $ dateFrom ,以及 $ read_info
<?php include 'dbconn.php';
$sqlbetweendate=('SELECT SUM(Pris) AS sum_pris FROM bestallning WHERE Datum BETWEEN "'.$dateFrom.'" AND"'.$dateTo.'"');
$result = mysqli_query($read_info,$sqlbetweendate);
while ($row =mysqli_fetch_array($result)) {
$test = $row['sum_pris'];
}
?>
<textarea id="id" cols="43" rows="7"><?= $test ?></textarea>
<?php include 'footer.php';?>