dpfwhb7470 2014-06-29 09:10
浏览 57

如何从javascript函数获取输入值以便将它们添加到数据库?

i have a following code in form.js

     var c=0;
     var b=0;
     function myCreateFunction()
    {

    var table = document.getElementById("myTable");
    {
        var row = table.insertRow(1);
        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        var cell3 = row.insertCell(2);
        var cell4 = row.insertCell(3);
        var cell5 = row.insertCell(4);
        var cell6 = row.insertCell(5);
        var cell7 = row.insertCell(6);


        cell1.innerHTML = c+1;
        cell2.innerHTML = "<input id='inp1' type='text' name='inpu1'>";
        cell3.innerHTML = "<input id='inp2' type='text' name='inpu2'>";
        cell4.innerHTML = "<input id='inp3'type='text' name='inpu3'>";
         cell5.innerHTML = "<input id='inp4' type='text' name='inpu4'>";
        cell6.innerHTML = "<input id='inp5' type='number' name='inpu5'>";


        c++;
        b=0;

     }
 }

now i want to get values from inpu1,inpu2,inpu3,inpu4,inpu5 and post them on to database using submit.php How can this be done ??

  • 写回答

2条回答 默认 最新

  • douai2499 2014-06-29 09:16
    关注

    This function will do it for you:

    function post() {
    
        var xhr = new XMLHttpRequest();
        xhr.open( 'POST', 'submit.php', true );
        xhr.addRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset = utf-8');
        xhr.send( 'inp1='+inp1.value+'&inp2='+inp2.value+'&inp3='+inp3.value+'&inp4='+inp4.value+'&inp5='+inp5.value );
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比