Javascript 为什么我的$\u帖子不进入结果页面
我进退两难,似乎无法克服。场景是我有两个选择列表框boxdest和boxdest2 其目的是使用boxdest中的项目填充boxdest2,它成功地实现了这一点。然而,当我发送到结果页面进行处理时,boxdest将通过,而不是boxdest2来保存项目。有趣的是,boxdest似乎正在发送正确的数据,而实际上,数据是通过boxdest2发送的 如果有人能指出我错在哪里,我将不胜感激。谢谢Javascript 为什么我的$\u帖子不进入结果页面,javascript,php,jquery,Javascript,Php,Jquery,我进退两难,似乎无法克服。场景是我有两个选择列表框boxdest和boxdest2 其目的是使用boxdest中的项目填充boxdest2,它成功地实现了这一点。然而,当我发送到结果页面进行处理时,boxdest将通过,而不是boxdest2来保存项目。有趣的是,boxdest似乎正在发送正确的数据,而实际上,数据是通过boxdest2发送的 如果有人能指出我错在哪里,我将不胜感激。谢谢 <?php $conn = mysql_connect("localhost","root",
<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("sample",$conn);
$result = mysql_query("SELECT * FROM boxes where department = '{$_GET['dept']}' ORDER BY custref ASC");
?>
<select name="boxdest[]" id="boxdest" size="7" multiple="multiple">
<?php
$i=0;
while($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row["custref"];?>"><?php echo $row["custref"];?></option>
<?php
$i++;
}
?>
</select>
<span style="display: inline-block; width: 70px; height: 82px; padding-left: 10px; padding-right: 10px; vertical-align: top;margin-top:35px;">
<input type="button" id="submit2" name="submit2" value=">" />
<input type="button" id="submit3" name="submit3" value="<" />
</span>
<select name="boxdest2[]" id="boxdest2" size="7" multiple="multiple"></select>
jquery代码
<script type="text/javascript">
$(document).ready(function () {
// initial list, as fetched from the server
var initialList = $('#boxdest > option')
.map(function () { return this.value; }).get();
/**
* @param {string} source
* @param {string} destination
*/
function exchangeLists(source, destination) {
// find all selected items on the source list
var selected = $(source + ' > option:selected');
// move them to the destination list
$(destination).append(selected.clone());
// remove from the source list
selected.remove();
// sort the destination list
var list = $(destination + ' > option').clone().sort(function (a, b) {
if (initialList.indexOf(a.value) < initialList.indexOf(b.value)) {
return -1;
}
if (initialList.indexOf(a.value) > initialList.indexOf(b.value)) {
return 1;
}
return 0;
});
// replace current destination list with the sorted one
$(destination).empty().append(list);
}
$('#submit2').click(function () {
exchangeLists('#boxdest', '#boxdest2');
});
$('#submit3').click(function () {
exchangeLists('#boxdest2', '#boxdest');
});
});
</script>
您是否确保项目在框之间移动后被选中?按原样,当您将项目从左向右移动时,移动后不会选择它们,因此不会过账。如果在提交表单之前重新选择每个框中的项目(例如,按住shift键并单击),则会正确发布这些项目 您的代码易受攻击。应使用或准备带有绑定参数的语句,如中所述。停止使用mysql_*函数。自2013年6月第5.5版起已弃用,自2015年12月第7.0版起已删除。而是将or函数与and一起使用。我知道Alex。但是,由于我只在当地工作,与此无关。这对我的问题有什么帮助?正如其他人所指出的,一定要看看像49438这样的网站。对不起,我不明白你的回答。从listbox1中删除后,如何再次选择它们。我可以看到他们正在被移动到第二个列表框。感谢您的代码在我尝试时对我非常有效,但我注意到,当项目从第一个列表移动到第二个列表时,它们不会保持选中状态,因此不会回发。将某些项目移动到第二个列表后,按住shift键并单击以选择第二个列表中的项目,然后提交表单。否则,当表单发回时,不会选择任何内容,因此项目不在$\u POST中。您可能需要更改jQuery,以便在项目移动到第二个列表后,第二个列表中的所有内容都被选中。感谢您的回复。我的问题是,为什么会这样?感谢您的任何意见