Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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 使一行可点击_Php_Javascript_Ajax - Fatal编程技术网

Php 使一行可点击

Php 使一行可点击,php,javascript,ajax,Php,Javascript,Ajax,我正在创建一个社交网站。我在search.php中有一个文本框,用于搜索存储在数据库中的场馆。当用户开始键入场馆名称时,存储在数据库中的场馆名称列表应加载到divvenuesearch。这很好。我的问题是我需要使divvenuesearch中的行可单击,这样当用户单击某一行时,该值应该出现在文本框中 search.php <script language="javascript"> function showData(str) { if (str.length==0)

我正在创建一个社交网站。我在
search.php
中有一个文本框,用于搜索存储在数据库中的场馆。当用户开始键入场馆名称时,存储在数据库中的场馆名称列表应加载到div
venuesearch
。这很好。我的问题是我需要使div
venuesearch
中的行可单击,这样当用户单击某一行时,该值应该出现在文本框中

search.php

<script language="javascript">
function showData(str)
{
    if (str.length==0)
    {
        document.getElementById("venuesearch").innerHTML="";
        document.getElementById("venuesearch").style.border="0px";
        return;
    }
    var venue_data = document.getElementById("venue").value;
    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("venuesearch").innerHTML=xmlhttp.responseText;
            document.getElementById("venuesearch").style.border="1px solid #A5ACB2";    
            document.getElementById("venuesearch").style.zIndex = "100";
        }
    }
    xmlhttp.open("GET","aj_search.php?venue="+str,true);
    xmlhttp.send();
}
 </script>
 </head>

<body>

<input id="venue" name="venue" type="text" onkeyup="showData(this.value)" value="Tag venue name"/>
<div id="venuesearch">
</div>
</body>

函数showData(str)
{
如果(str.length==0)
{
document.getElementById(“venuesearch”).innerHTML=“”;
document.getElementById(“venuesearch”).style.border=“0px”;
返回;
}
var VINCE_data=document.getElementById(“VINCE”).value;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“venuesearch”).innerHTML=xmlhttp.responseText;
document.getElementById(“venuesearch”).style.border=“1px solid#A5ACB2”;
document.getElementById(“venuesearch”).style.zIndex=“100”;
}
}
open(“GET”,“aj_search.php?venture=“+str,true”);
xmlhttp.send();
}
aj_search.php

  <?php
$dbhandle=mysql_connect("localhost","root","")or die("Unable to connect");
$select=mysql_select_db("scenekey",$dbhandle) or die("Unable to connect");

    if(isset($_GET['venue']))
    {
  $venue_name = $_GET['venue'];
    }
    $hint='';
    $query_get_venue = "SELECT * from sk_accounts WHERE acnt_member_class='venue' and acnt_fname LIKE '".$venue_name."%'";

     $result_query_get_venue = mysql_query($query_get_venue);
     $row_count = mysql_num_rows($result_query_get_venue);
 if($row_count > 0)
 {
    $hint = "<table>";
     while($row = mysql_fetch_array($result_query_get_venue))
     {

         $act_fname = $row['acnt_fname'];
         $act_lname = $row['acnt_lname'];
         $act_name = $act_fname . ' ' . $act_lname;
         $hint.= "<tr><td>".$act_name."</td></tr>";
     }
     $hint .= "</table>";
 }
     if ($hint == "")
     {
   $response="no suggestion";
     }
     else
     {
 $response=$hint;
      }

     //output the response
     echo $response;
      ?>

添加
id
class
,然后为相同或添加
javascript
功能设置单击事件

 $hint.= "<tr onClick ='hintVal(".$act_name.");'><td>".$act_name."</td></tr>";

为什么不能使用
jqueryautocomplete


$(this.val()
是Jquery,他没有使用它。@sahal在这种情况下,OP可以在函数本身中传递tr值:
hintVal(“.act\u name”);
无论如何OP没有响应:)。懒惰的OP似乎be@vimalnath它不起作用。我写了这样的代码{$hint.='.$act_name.“;}@vimalnath我在(aj_search.php)中写了上面的语句,在(search.php)中写了js方法。你解决问题了吗?
function hintVal(trVal) {
 alert('tr clicked');
 alert('tr value:'+trVal);
}