使用 ajax 提交文本框的 id 和值


Submit id and value of textbox with ajax

嘿伙计们,当使用输入数字时,我试图处理文本字段的 id 和值。我目前正在使用此脚本提交:

<script>
function warenkorb(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","towarenkorb.php?q="+str,true);
xmlhttp.send();
}
</script>

我的文本框看起来像这样:

<input id="'.$resultarray3['ID'].'_k" onchange="warenkorb(this.value)" type="text">

那么我必须更改我的脚本正在这样做:

xmlhttp.open("GET","towarenkorb.php?q="+str+"&ID=" + rtr,true);

希望有人能帮助我。

怎么样

function warenkorb(str, id) {

<input id="'.$resultarray3['ID'].'_k" onchange="warenkorb(this.value,'.
   $resultarray3['ID'].')" type="text">

请记住,我假设您的ID是一个整数。如果不是,您可能需要将$resultarray3['ID']括在引号中。