du7979 2016-01-19 21:43
浏览 43
已采纳

html表单字段在提交表单之前从sql数据库获取内容?

I try to get content from database before submitting the form.I call javascript function in onload method.When I Directly write php code into textarea it works but when I append same php content to textarea through JS its not working, total php content only shown in textarea.Thanks in advance.

var parent=document.getElementById("textarea");
var child=document.createTextNode(' <?php '+
' include "conn.php"; '+
' $q1="SELECT `breakfast` FROM `foodmenu` WHERE `day`=\'Wednesday\'"; '+
' $result=$conn->query($q1); '+
' while($row=$result->fetch_assoc()) '+
' { '+
' echo $row["breakfast"]; '+
' } '+
' ?> ');
parent.appendChild(child);

For your easy reference

  • 写回答

1条回答 默认 最新

  • drfb52000 2016-02-24 22:40
    关注

    call this method while load page, the field content get load from sql database. getmenu.php file have business logic to get query

    $("select").on('change',function(){
    
        $.ajax({
            type: "POST",
            url: "getmenu.php",
            data: {
                day: $("#showday").val()  ,
                forwhat: $("#tab .active a").text()
            },
            success: function (Response) {
                $("#menu").val(Response.trim());
            } // you had an extra );
        });
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?