带有声明参数的JavaScript post
我希望能够在php循环中编辑单个行。我这里有一个脚本,我认为它几乎是完美的,只是我不知道如何为“PriorityForm”添加值带有声明参数的JavaScript post,javascript,php,Javascript,Php,我希望能够在php循环中编辑单个行。我这里有一个脚本,我认为它几乎是完美的,只是我不知道如何为“PriorityForm”添加值 <script type="text/jscript"> function PriorityInfo(Value) { $.post("updatenote.php?ID="+Value, { Note: PriorityForm.Note.value}, function(output) {
<script type="text/jscript">
function PriorityInfo(Value) {
$.post("updatenote.php?ID="+Value, { Note: PriorityForm.Note.value},
function(output) {
$("#Priority"+Value).html(output).show();
});
}
</script>
这会导致JavaScript无法运行,所以我很确定这是一个语法错误。
我错了,下面是PHP代码:
<?php
$info0 = "SELECT * FROM CT:GTMQuestionPoints WHERE Question = 'Priority' AND PointLossNote NOT LIKE ''";
$rs0=odbc_exec($connq,$info0);
while($row = odbc_fetch_array($rs0)) {
$ID = "" . $row["ID"] . "";
$Note = "" . $row["PointLossNote"] . "";
$Points = "" . $row["Points"] . "";
echo '
<table>
<tr>
<td style="width: 700px"><form name="PriorityForm'.$ID.'"><input name="Note" type="text" value ="'.$Note.'" style="width: 700px"></td>
<td style="width: 100px"><input name="Points" type="text" value ="' . $Points . '" style="width: 100px"></td></form>
<td style="width: 180px"><input name="updatepriority" type="button" value="Update" onclick="PriorityInfo(''.$ID.'')"><div id="Priority'.$ID.'"></div></td>
<td style="width: 180px"><form method="POST" action="rmsdeletenote.php?Priority=' . $Note . '"><input name="modify" type="submit" value="Remove"></td></form>
</tr>
</table>
';
}
?>
查看POST参数“{Note:PriorityForm.Note.value}”,您使用的是PriorityForm,就好像它是一个对象一样。但是根据您提供的代码,您没有在任何地方声明“PriorityForm”变量。因此,您可能需要考虑使用jQuery从名为“Note”的文本输入中获取值。有很多方法可以做到这一点。这里有一个:
<script type="text/javascript">
function PriorityInfo(Value) {
var args = new Object();
args["Note"] = $("input[name='Note']").value;
$.post("updatenote.php?ID="+Value, args,
function(output){
//other code here
});
}
</script>
函数优先级信息(值){
var args=新对象();
args[“Note”]=$(“input[name='Note'])。值;
$.post(“updatenote.php?ID=“+Value,args,
功能(输出){
//这里还有其他代码
});
}
试试这个:第一步,主页上的PHP
<?php
;//extend the form around the loop, and get rid of the form for the remove button (replacing with javascript)//
echo '<form name="PriorityForm">';
$info0 = "SELECT * FROM CT:GTMQuestionPoints WHERE Question = 'Priority' AND PointLossNote NOT LIKE ''";
$rs0=odbc_exec($connq,$info0);
while($row = odbc_fetch_array($rs0)) {
$ID = "" . $row["ID"] . "";
$Note = "" . $row["PointLossNote"] . "";
$Points = "" . $row["Points"] . "";
//give each field name a unique name//
echo '
<table>
<tr>
<td style="width: 700px"><input name="Note'.$ID.'" type="text" value ="'.$Note.'" style="width: 700px"></td>
<td style="width: 100px"><input name="Points'.$ID.'" type="text" value ="' . $Points . '" style="width: 100px"></td>
<td style="width: 180px"><input name="updatepriority" type="button" value="Update" onclick="PriorityInfo(''.$ID.'')"><div id="Priority'.$ID.'"></div></td>
<td style="width: 180px"><input name="modify" type="button" value="Remove" onclick="Remove(''.$ID.'')">
</tr>
</table>
';
}
echo '</form>';
?>
<!-- send the specific ID and serialize everything else to the updatenote.php page-->
<script type="text/javascript">
function PriorityInfo(Value) {
$.post("updatenote.php?ID="+Value,
$('form[name="PriorityForm"]').serialize(),
function (output) {
$("#Priority"+Value).html(output).show();
});
}
</script>
<!-- send the specific ID to the deletenote.php page-->
<script type="text/jscript">
function Remove(Value) {
location.href = "deletenote.php?ID="+Value;
}
</script>
第二步:主页面上的JavaScript
<?php
;//extend the form around the loop, and get rid of the form for the remove button (replacing with javascript)//
echo '<form name="PriorityForm">';
$info0 = "SELECT * FROM CT:GTMQuestionPoints WHERE Question = 'Priority' AND PointLossNote NOT LIKE ''";
$rs0=odbc_exec($connq,$info0);
while($row = odbc_fetch_array($rs0)) {
$ID = "" . $row["ID"] . "";
$Note = "" . $row["PointLossNote"] . "";
$Points = "" . $row["Points"] . "";
//give each field name a unique name//
echo '
<table>
<tr>
<td style="width: 700px"><input name="Note'.$ID.'" type="text" value ="'.$Note.'" style="width: 700px"></td>
<td style="width: 100px"><input name="Points'.$ID.'" type="text" value ="' . $Points . '" style="width: 100px"></td>
<td style="width: 180px"><input name="updatepriority" type="button" value="Update" onclick="PriorityInfo(''.$ID.'')"><div id="Priority'.$ID.'"></div></td>
<td style="width: 180px"><input name="modify" type="button" value="Remove" onclick="Remove(''.$ID.'')">
</tr>
</table>
';
}
echo '</form>';
?>
<!-- send the specific ID and serialize everything else to the updatenote.php page-->
<script type="text/javascript">
function PriorityInfo(Value) {
$.post("updatenote.php?ID="+Value,
$('form[name="PriorityForm"]').serialize(),
function (output) {
$("#Priority"+Value).html(output).show();
});
}
</script>
<!-- send the specific ID to the deletenote.php page-->
<script type="text/jscript">
function Remove(Value) {
location.href = "deletenote.php?ID="+Value;
}
</script>
函数优先级信息(值){
$.post(“updatenote.php?ID=“+Value,
$('form[name=“PriorityForm”]')。序列化(),
功能(输出){
$(“#优先级”+值).html(输出).show();
});
}
函数删除(值){
location.href=“deletenote.php?ID=“+Value;
}
第三步:updatenote.php的附加/替换php代码
// get the ID//
If(!empty($_REQUEST['ID'])){$ID = ($_REQUEST['ID']);}
//add field name and ID to isolate the correct one//
$Note = "Note" . $ID;
$Points = "Points" . $ID;
//then retrieve only the one with the ID
If(!empty($_POST[$Note])){$NoteResult = $_POST[$Note];}
If(!empty($_POST[$Points])){$PointsResult = $_POST[$Points];}
echo $ID;
echo '<br>';
echo $NoteResult;
echo '<br>';
echo $PointsResult;
//获取ID//
如果(!empty($_请求['ID']){$ID=($_请求['ID']);}
//添加字段名和ID以隔离正确的字段//
$Note=“Note”$身份证件
$Points=“Points”$身份证件
//然后仅检索ID为的
如果(!empty($_POST[$Note]){$notesult=$_POST[$Note];}
如果(!empty($_POST[$Points]){$PointsResult=$_POST[$Points];}
echo$ID;
回声“
”;
回声$notesult;
回声“
”;
echo$PointsResult;
这可能不是最干净的方法,但对我来说很有效。使用数组或对象而不是变量。请参阅和其他许多内容:什么是PHP循环?如果你想问一个关于PHP的问题,发布你的PHP代码。什么是
PriorityForm
?它在哪里声明,它包含什么值?