Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript中mysql数据库的数据填充下拉列表_Javascript_Php_Database_Select_Menu - Fatal编程技术网

使用javascript中mysql数据库的数据填充下拉列表

使用javascript中mysql数据库的数据填充下拉列表,javascript,php,database,select,menu,Javascript,Php,Database,Select,Menu,我正在创建一个表格,它要求考生发布他们以前的教育历史信息-这里是表格的截图和附加的代码 [IMG] [IMG] 以下是我的javascript代码: <script> function removeFields1(){ //var container1 = document.getElementById("container1"); //container1.removeChild(input); } function addFields1(){ var

我正在创建一个表格,它要求考生发布他们以前的教育历史信息-这里是表格的截图和附加的代码

[IMG]

[IMG]

以下是我的javascript代码:

<script>
function removeFields1(){
//var container1 = document.getElementById("container1");
//container1.removeChild(input);


}
    function addFields1(){
        var container = document.getElementById("container1");

        var option = document.createElement("select"); //? how do I fix this up


        //option.text = "Kiwi";
        //container.add(option);
        container.appendChild(option);//? how do I fix this up


        container.appendChild(document.createTextNode("Address: "));//Address form

        var input = document.createElement("input");
        input.type = "text";
        input.id = "instaddress";
        input.name = "instaddress";
        input.size = 20;
        input.maxlenth = 20;
        container.appendChild(input);

        container.appendChild(document.createTextNode("From: "));   // which year the person started        
        var from = document.createElement("input");                 // studying in that institution
        from.type = "text";
        from.id = "from";
        from.name = "from";
        from.size = 4;
        from.maxlenth = 4;
        container.appendChild(from);

        container.appendChild(document.createTextNode("To: "));     // which year the person finished 
        var to = document.createElement("input");                   // studying in that institution
        to.type = "text";
        to.id = "to";
        to.name = "to";
        to.size = 4;
        to.maxlenth = 4;
        container.appendChild(to);

        container.appendChild(document.createTextNode(" Did You Graduate?: Yes"));    // radio buttons whether someone graduated or not          

        var grad = document.createElement("input");
        grad.type = "radio";
        grad.id = "graduate";
        grad.name = "graduate";
        grad.value = "yes"; //yes value for radio button
        container.appendChild(grad);

        container.appendChild(document.createTextNode(" No "));
        var grad1 = document.createElement("input");
        grad1.type = "radio";
        grad1.id = "graduate";
        grad.value = "no"; //no value for radio button
        container.appendChild(grad1);

        container.appendChild(document.createTextNode(" Certificate: "));

        var certificate = document.createElement("input");
        certificate.type = "text";
        certificate.id = "certificate";
        certificate.name = "certificate";
        input.size = 25;
        input.maxlenth = 25;
        container.appendChild(certificate);

        var addInstitution = document.getElementById(" Add");
        var removeInstitution = document.getElementById("Remove");
     //  container.removeChild(addInstitution);

        //create and insert input/text

        //create and insert button
        addInstitution = document.createElement("a");
        addInstitution.id="Add"
        addInstitution.href="#";
        addInstitution.text="Add";
        addInstitution.onclick=function(){addFields1();};

        removeInstitution = document.createElement("a");
        removeInstitution.id="Remove"
        removeInstitution.href="#";
        removeInstitution.text=" Remove";
        container.appendChild(addInstitution);
        container.appendChild(removeInstitution);
        //removeInstitution.onclick=function(){removeFields1();};
        //
        container.appendChild(document.createElement("br"));

    }

</script>
你们有谁能帮我修改Javascript代码吗

下面是需要更正的代码片段,以便我可以在每次按下Add链接时使用Javascript函数下拉菜单列表:

 var option = document.createElement("select"); //? how do I fix this up

 var option = document.createElement("select"); //? how do I fix this up
 //option.text = "Kiwi";
 //container.add(option);
 container.appendChild(option);//? how do I fix this up

你是说像这样的

var slct = document.createElement("select"); //? how do I fix this up
container.appendChild(slct);//? how do I fix this up

//some php code that is generating js code
<?php
    $sql1a = "SELECT * FROM institution ORDER BY institution asc";
    $smt1a = $dbs->prepare($sql1a);
    $smt1a -> execute();
    while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
    {
        echo("var opt=document.createElement(\"option\");\r\n");
        echo("opt.value=$row1a[institution];\r\n");
        echo("opt.text =$row1a[institution];\r\n");
        echo("slct.appendChild(opt);");
    }
?>

slct.value=<?php echo $_GET['id3']; ?>;

我希望这能有所帮助/

yoo-hoo。。。有人在家吗?有人能帮我吗?我现在就去试试Arash…我想这就是我想要的问题是什么?你能给我发一份通用的源代码吗?输出?我应该将生成的源代码发送到哪里?哦,我是指输出:数据输出结果为nothing-null-zilch-nada!
 var option = document.createElement("select"); //? how do I fix this up

 var option = document.createElement("select"); //? how do I fix this up
 //option.text = "Kiwi";
 //container.add(option);
 container.appendChild(option);//? how do I fix this up
var slct = document.createElement("select"); //? how do I fix this up
container.appendChild(slct);//? how do I fix this up

//some php code that is generating js code
<?php
    $sql1a = "SELECT * FROM institution ORDER BY institution asc";
    $smt1a = $dbs->prepare($sql1a);
    $smt1a -> execute();
    while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
    {
        echo("var opt=document.createElement(\"option\");\r\n");
        echo("opt.value=$row1a[institution];\r\n");
        echo("opt.text =$row1a[institution];\r\n");
        echo("slct.appendChild(opt);");
    }
?>

slct.value=<?php echo $_GET['id3']; ?>;