简体   繁体   English

通过PHP分配id将变量导入JS

[英]Getting variable into JS via PHP assigned id

I have the following Javascript to generate a silent call to another sheet to update a database value without refreshing the page 我有以下Javascript来生成对另一个工作表的静默调用,以更新数据库值而不刷新页面

function UpdateDB(table,column,type){
    var value = $("#Assigned").val();

    $.post("UpdateValuation.php?Table=" + table + "&Value=" + value + "&Column=" + column + "&Type=" + type, {}).done();
};

This works perfectly but only for the "Assigned" table row since it is statically assigned. 这非常有效,但仅适用于“已分配”表行,因为它是静态分配的。

I use the following php to generate the table entry with button 我使用以下php生成带有按钮的表条目

print "<tr><td>" . $stuff['Status'] . "</td><td ><input type=\"text\" id=\"" . $stuff['Status'] . "\" name=\"" . $stuff['Status'] . "\" value=". $stuff['Value'] ." size = \"4\" style = \"text-align: center\"/><button onclick=\"UpdateDB('NOCstatus','Status','". $stuff['Status'] ."');\">Update</button></td></tr>";

Which after variables are assigned looks like this for my "Pending" row 为我的“待定”行分配了哪些变量后的变量

<input id="Pending" type="text" style="text-align: center" size="4" value="120" name="Pending">    </input>
<button onclick="UpdateDB('NOCstatus','Status','Pending');">
Update
</button>

My problem is that passing "this.value" or trying to use a variable in the javascript portion I always come up with a blank value, the only time I can get a value to be correct is by statically assigning the "#Assigned" or "#Pending" in the value field. 我的问题是传递“this.value”或尝试在javascript部分中使用变量我总是想出一个空值,唯一一次我能得到一个正确的值是通过静态分配“#Assigned”或值字段中的“#Pending”。 I have hundreds of entries so I don't want to write the function over for each of these. 我有数百个条目,所以我不想为每个条目编写函数。 I know there is probably something extremely simple I am missing but I cannot get the pieces to fit. 我知道可能有一些非常简单的东西,但是我无法让这些东西适合。

I need to pass the typed in value in the input field to the function to update the database. 我需要将输入字段中的输入值传递给函数以更新数据库。 Please help. 请帮忙。

function UpdateDB(table,column,type){
    var value = $('#'+type).val();

    $.post("UpdateValuation.php?Table=" + table + "&Value=" + value + "&Column=" + column + "&Type=" + type, {}).done();
};    

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM