Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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
Php document.getElementById无法更新文本框值_Php_Javascript_Html - Fatal编程技术网

Php document.getElementById无法更新文本框值

Php document.getElementById无法更新文本框值,php,javascript,html,Php,Javascript,Html,我有一个生成表行的php代码: <table id="listOfProducts" name="listOfProducts" width="100%"> <tr> <th>Item</th> <th>Product</th> <th>Description</th> <th>Unit Price</th> <th

我有一个生成表行的php代码:

    <table id="listOfProducts" name="listOfProducts" width="100%">
    <tr>
    <th>Item</th>
    <th>Product</th>
    <th>Description</th>
    <th>Unit Price</th>
    <th>Select</th>
    <th>Qty</th>
    <th>Amount</th>
    </tr>
    Products on List: 2
    <tr class="row1" id="tr1">
    <td id="pid1">1</td>
    <td id="pname1">Paint Brush</td>
    <td id="pdesc1">Premium Brand </td>
    <td id="pprice1">24</td>
    <td><input type="checkbox" id="chk1" checked></td>
    <td><input type="text" style="width:50px;" onkeyup="getall('tr1','ttp1')" id="1"/></td>
    <td><input type="text" id="ttp1" name="ttp1" value="00"/></td>
    </tr>
    <tr class="row1" id="tr2">
    <td id="pid2">2</td>
    <td id="pname2">Iron Nails</td>
    <td id="pdesc2">Stainless</td>
    <td id="pprice2">50</td>
    <td><input type="checkbox" id="chk2" checked></td>
    <td><input type="text" style="width:50px;" onkeyup="getall('tr2','ttp2')" id="2"/></td>
    <td><input type="text" id="ttp2" name="ttp2" value="00"/></td>
    </tr>
    </table>

我不知道真正的问题是什么。我检查了包含文本框的id是否已成功传递,并且它是…

您可以尝试使用jquery更新它:$+prdno.valans

我只是复制并粘贴了您的代码,并在顶部添加了jquery include v1.7.2,它完全可以在Opera、FF和Chrome中使用

当询问javascript问题时,呈现的html总是更有用。从浏览器的视图Source看,您的控制台是否显示任何错误?根本没有错误,这是有效的。。。检查这里:您需要将所有代码放在$function{..here..}中。我做了同样的操作,它工作正常,您认为我的代码有什么问题吗?您认为这与php值有关吗?哦,是的,我发现了,这是关于我的脚本tagsHi@Locohost的安排,我现在的问题是通过数组将表中的检查值传递给php控制器。你有什么建议吗?非常感谢你@乌邦古1947676:当然。因此,您将捕获一个按钮单击并使用jQuery获取表单值。下一步是使用ajax post将数据发送到服务器端PHP脚本。你可以在这里找到你需要的东西http://api.jquery.com/jQuery.ajax/@Umpong_1947676:或者你可以试试这个。可能更容易,但我还没试过。今天下班后我会摆弄一下这个。@Umpong_1947676:你一定要去看看。只是一些JS/jQuery代码,包装了编写表单ajax帖子的混乱部分。看起来很简单。@Umpong_1947676:嘿,我只是想在这里继续。我尝试了上面的jQuery表单插件链接,效果非常好!我现在用它来上传ajax文件。您必须提供自己的服务器端代码,但这很简单:-
    function getall( strId, prdno){
var tmpObj = document.getElementById(strId);
var myobj = $("#listOfProducts").find("tr#" + strId);
     alert("reported id for testing: " + tmpObj.getAttribute("id"));
 //alert (prdno);
    var prdid= myobj.find('td:eq(0)').text();
    var prdname= myobj.find('td:eq(1)').text();
    var prddesc= myobj.find('td:eq(2)').text();
var prduprice = parseFloat(myobj.find('td:eq(3)').text());
var quan = myobj.find('td:eq(5) input').val();
var ans=prduprice * quan;
document.getElementById(prdno).value=ans;       
    }